Jump to content

Remove a html tag in a $string


karthikeyan_coder

Recommended Posts

Hello,

      I am parsing a rss. While parsing i am getting some  images inside the description. Actually i dont want it. so i try to remove <img tags.

 

$desc = "this is the sample image <img src='image.jpg'> have a look on it";

 

I need $desc like "this is the sample image <!-- <image src='image.jpg'> --> have a look on it"

 

any help?

Link to comment
https://forums.phpfreaks.com/topic/46637-remove-a-html-tag-in-a-string/
Share on other sites

http://us.php.net/manual/en/function.strip-tags.php

 

$desc = "this is the sample image <img src='image.jpg'> have a look on it";
$desc = strip_tags($desc, '<a><p><br>'); // the second param is for allowable tags. 

 

However this will remove that reference completely. If you want to replace it with how you have it above, I would suggest ereg_replace and use regex to replace the content.

 

www.php.net/ereg_replace

www.php.net/regex

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.