Sam Granger Posted October 29, 2007 Share Posted October 29, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/75240-delete-rags-from-string/ Share on other sites More sharing options...
severndigital Posted October 29, 2007 Share Posted October 29, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/75240-delete-rags-from-string/#findComment-380538 Share on other sites More sharing options...
Dragen Posted October 29, 2007 Share Posted October 29, 2007 I'm not sure, but this might work: <?php $url = '[img=http://www.mydomain.com/myimage.png]'; $s = array('/\[img\]/', '/\[\/img\]/'); $img = preg_replace($s, '', $url); echo $img; ?> Quote Link to comment https://forums.phpfreaks.com/topic/75240-delete-rags-from-string/#findComment-380561 Share on other sites More sharing options...
Dragen Posted October 29, 2007 Share Posted October 29, 2007 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; ?> Quote Link to comment https://forums.phpfreaks.com/topic/75240-delete-rags-from-string/#findComment-380574 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.