I am trying to figure out how to move an image in a small paragraph of text using regex, so that for example:
this is a <img src="image.jpg" /> paragraph
turns into
<img src="image.jpg" /> this is a paragraph
Does anyone have any ideas please
Simplified match, but will do for faux-XHTML:
$src = preg_replace('/^(.*?)(<img[^>]+>)/m', '$2 $1', $src);
| | | |
start of line | the img tag switching
everything that follows positions
This assumes you consider the start of a line the start of a paragraph.
Since this is your second regex question, I'd like to hint at reading http://www.php.net/manual/en/reference.pcre.pattern.syntax.php and http://regular-expressions.info/