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 Quote Link to comment 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 Quote Link to comment 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">')); ?> Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted October 23, 2007 Author Share Posted October 23, 2007 Thanks, Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.