Jump to content

is this possible?


ted_chou12

Recommended Posts

<img src=\"/users/smilies/rolleyes.gif\" alt=\"Roll Eyes\">

<img src=\"/users/smilies/cheesy.gif\" alt=\"Cheesy\">

is it possible to add "http://domain.com" in front using preg_replace? so they become:

<img src=\"http://domain.com/users/smilies/rolleyes.gif\" alt=\"Roll Eyes\">

<img src=\"http://domain.com/users/smilies/cheesy.gif\" alt=\"Cheesy\">

Thanks.

Ted

Link to comment
https://forums.phpfreaks.com/topic/74442-is-this-possible/
Share on other sites

I've tried this:

$string = preg_replace("<img src=\"/users/smilies/(.+?)\.gif\" alt=\"(.+?)\">", "<img src=\"http://domain.com/users/smilies/\\1.gif\" alt=\"\\2\">", $entrycontent);
echo $string;

But it has extra <> in the out put, and when I added ` and `is at the front and the end, the output seems to be what I wanted (without <>), what do the ` and `is do?

Thank you for your help.

Ted

Link to comment
https://forums.phpfreaks.com/topic/74442-is-this-possible/#findComment-376176
Share on other sites

This is very specific--it assumes that src is the first attribute in the image tag, and that double quotes are being used:

 

<?php
echo htmlentities(preg_replace('/(?<=<img src=")(?!http:)/', 'http://domain.com', '<img src="/users/smilies/rolleyes.gif" alt="Roll Eyes">'));
?>

Link to comment
https://forums.phpfreaks.com/topic/74442-is-this-possible/#findComment-376197
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.