Jump to content

Regex find and replace invalid img tags.


noexcal

Recommended Posts

I need to replace invalid img tags on submit.

 

PHP will preg_replace <img src="http://somesite.com/script.php"> but will allow <img src="http://somesite.com/image.gif"> something like

 

$field = preg_replace('!\<img(.*)src=\"^(http|https)\:\/\/(.*)\"(.*)\.^(jpg|gif|jpeg|png)(.*)\>!i', '..', $field);

 

That does not work, but you get the main idea.

I do not need some long code, I know this can be done simple, because I have done similar stuff.. For some reason I just get stuck on this one.

Link to comment
https://forums.phpfreaks.com/topic/94443-regex-find-and-replace-invalid-img-tags/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.