I needed to wrap all the images in the text in a div tag, after removing paragraphs, if any. I found a similar example of a regular expression for another tag, changed it to fit my task. Everything works, but I would like to figure out how. In the help on regular expressions, I could not find the role of the ~ sign anywhere, but if you remove it, the code stops working. Tell me, please, what this sign means and how to use it properly.
$search = array( '(<p[^>]*?>(<img[^>]*?>)</p>)', '~(<img[^>]*?>)~' ); $replace = array( '$1', '<div>$1</div>' ); $result = preg_replace($search, $replace, $text);