susanBuck Posted August 21, 2007 Share Posted August 21, 2007 I need my preg_replace to ignore white space.. for example - I have a string that holds some text and a URL surrounded by some bulletin board img tags $message = "Hi this is a post in a forum. Check out this image : [img=http://link.com/image.jpg]"; this preg_replace takes the url from inbetween the img tags and passes it to a function called shrinkImage $message = preg_replace('#\[img\]((ht|f)tps?://[^www.photojojo.com])([^\s<"]*?)\.(jpg|jpeg|png|gif).*\[/img\]#e', 'shrinkImage(\'$1$3.$4\', true)', $message); I need the above preg_replace to work even if there are spaces between the img tags... ie.. $message = "Hi this is a post in a forum. Check out this image : [img= http://link.com/image.jpg ]"; or $message = "Hi this is a post in a forum. Check out this image : [img=http://link.com/image.jpg ] "; or $message = "Hi this is a post in a forum. Check out this image : [img= http://link.com/image.jpg] "; Any help? Quote Link to comment Share on other sites More sharing options...
effigy Posted August 21, 2007 Share Posted August 21, 2007 #\[img\]\s*((ht|f)tps?://[^www.photojojo.com])([^\s<"]*?)\.(jpg|jpeg|png|gif)\s*\[/img\]# [^www.photojojo.com] is not preventing a string match, but individual character matches. I think you want (?!www\.photojojo\.com) here. (jpg|jpeg|png|gif) can be reduced to (jpe?g|png|gif). Also, use (?: ... ) when you do not need to capture a group. 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.