Possible Duplicate:
Grabbing the href attribute of an A element
I have a cms where clients can make their own HTML newsletters. These are send to selected receivers with Swift mailer. Included in these newsletters are images that are linked to online sources. I want to embed these images in the e-mail itself, a feature that Swift mailer supports.
What I like to accomplish is that clients can create their own newsletter including linking to the images. When sending this linked images must be replaced by the code necessary to embed them in the e-mail. Therefor I need to replace the source of the images:
<img src="http://source/to/file.gif" />
to:
<img src="{$message->embed(Swift_Image::fromPath('http://http://source/to/file.gif'))}" />
The HTML content, including the linked images, is stored in a variable $content. I tried to replace the src with:
$content = preg_replace(
'/<img.*src="(.*?)".*?>/',
'<img src="' . $message->embed(Swift_Image::fromPath('\1"')) . '" />',
$content);