Jump to content

[SOLVED] How to remove [img] and [/img] tag


lily

Recommended Posts

Hi, I need to find the images from some text. The images are coded within tags img(I purposely put a space between img and ], so that you can see the tags). I have found a way to take off imgtag if there is no other text in string.

For example:

$RawBody="img"

$RawBody=preg_replace("#\[img\]([^?\['\"]+?)\.(gif|png|jpg|jpeg)\[/img\]#i", '\1.\2 ',$RawBody);

 

I will get image name: myimage.jpg. But if there is other text in $RawBody, then I can not get right result. For example, if I change $RawBody to:

$RawBody="This is my image img, other text";

$RawBody=preg_replace("#\[img\]([^?\['\"]+?)\.(gif|png|jpg|jpeg)\[/img\]#i", '\1.\2 ',$RawBody);

 

I will not be able to get result "myimage.jpg". What to do to get right image name in second case? Thanks for help!

Link to comment
https://forums.phpfreaks.com/topic/80300-solved-how-to-remove-img-and-img-tag/
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.