Jump to content

Delete rags from string


Sam Granger

Recommended Posts

Hello guys!

 

I currently have mysql db with a lot of content. Some of the content has [image]filename here......[/image] tags. How do I strip the strings from [image], [/image] and all the content inbetween these tags? I only want this for an RSS feed I am building, so don't want to update the DB.  :)

Link to comment
Share on other sites

if i am understanding your post correctly you should be able to get what you need from the preg_replace command

 

http://us3.php.net/manual/en/function.preg-replace.php

 

basically just search the string for what you are looking for and return a whitespace.

 

but you might run into some problems with the content between the [image][/image] tags.

 

hmmm...

now that i think about it,

seems like a job for a custom class or function.

 

see what we can come up with

 

 

 

 

 

 

 

Link to comment
Share on other sites

Actually scrap that last one.. I've got a better one here.

Makes the code shorter and also I've made it case insensitive so it'll work if the image tags are in caps as well:

<?php
$url = 'hghfhf[img=http://www.mydomain.com/myimage.png] hfghfhf';
$img = preg_replace('#(\[img\])([a-z0-9./:]+)(\[\/img\])#i', '$2', $url, -1, $c);

echo $img;
?>

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.