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? Link to comment https://forums.phpfreaks.com/topic/65984-regular-expressions-preg_replace-ignore-spaces/ 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. Link to comment https://forums.phpfreaks.com/topic/65984-regular-expressions-preg_replace-ignore-spaces/#findComment-329917 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.