ted_chou12 Posted October 23, 2007 Share Posted October 23, 2007 <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 More sharing options...
ted_chou12 Posted October 23, 2007 Author Share Posted October 23, 2007 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 More sharing options...
effigy Posted October 23, 2007 Share Posted October 23, 2007 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 More sharing options...
ted_chou12 Posted October 23, 2007 Author Share Posted October 23, 2007 Thanks, Link to comment https://forums.phpfreaks.com/topic/74442-is-this-possible/#findComment-376527 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.