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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.