tmh766 Posted February 6, 2010 Share Posted February 6, 2010 Hi everyone I have been trying for hours to understand a way to do this. I need to replace all instances of "http" all the way to the first space character (get a url), as long as it does not end in ".jpg",".gif"...etc I can match a URL, /(http[^\s]+)/i but cannot figure out a way to not match it if a picture extension is present in the end. Thank you! Quote Link to comment Share on other sites More sharing options...
MadTechie Posted February 7, 2010 Share Posted February 7, 2010 can you give some examples please. I assume http:\\www.domain.com\blar.html < - replaced with ? http:\\www.domain.com\blar.jpg < - NOT replaced Quote Link to comment Share on other sites More sharing options...
MadTechie Posted February 7, 2010 Share Posted February 7, 2010 try this $HTML = "test http:\\www.domain.comj\blar.html ing http:\\www.domain.com\test\blar.jpg http:\\www.domain.com\test\blar.html http:\\www.domain.com\blar.html http:\\www.domain.com\blar.gif http:\\www.domain.com\blar.php http:\\www.domain.com\blar.png http:\\www.domain.com\blar.html http:\\www.domain.com\blar.jpg"; $HTML = preg_replace('/\bhttp:\\\\\S+?\\\\[^.]*\.(jpg|png|gif)\S*\b/i', '', $HTML ); echo $HTML; 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.