Page 1 of 1

a remove attribute function

Posted: Wed Nov 12, 2003 7:29 am
by Castles
Hi, I'm usign strip_tags() to remove unwanted tags in some code I have but I would also like to remove unwanted tags in tags I want to keep.. eg '<a href='link.html' target='_blank'>link</a>' --- is there a function to remove the target attribute or do i need to do a search and replce sorta thing?

Posted: Wed Nov 12, 2003 7:41 am
by twigletmac
AFAIK there's no function for removing attributes (outside of the XML handling functions), you'll probably need a search and replace thingie. Depending on the complexity [php_man]str_replace[/php_man]() will probably suffice.

Mac

Posted: Wed Nov 12, 2003 9:20 am
by Castles
yep, thanks got it to work..

this is what i used:

Code: Select all

<?php
$content = str_replace(' ALIGN=\\\"LEFT\\\"',"",$content);
?>

lots of escape characters.. it was returning ALIGN=\\\"LEFT\\\" so yeah.. wanted to remove that.