a remove attribute function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Castles
Forum Newbie
Posts: 14
Joined: Tue Nov 04, 2003 10:21 am

a remove attribute function

Post 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?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
Castles
Forum Newbie
Posts: 14
Joined: Tue Nov 04, 2003 10:21 am

Post 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.
Post Reply