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
https://forums.phpfreaks.com/topic/75240-delete-rags-from-string/
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

 

 

 

 

 

 

 

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;
?>

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.