Page 1 of 1

Removing unwanted tags

Posted: Mon Mar 24, 2008 9:14 am
by Addos
Hi,
I’m trying to do the following.

if (<ul></ul> appear side by side within a script) remove them {
}else { leave all other <ul></ul> in place that contain content within them.


I have a script that’s producing some extra <ul></ul> i.e. without text within them and simply want to remove them before I print to the browser.

I’ve tinkered with the following and tried strip_tags too but neither are really giving me the result. Is there a function that I can use to do this?
Thanks for any help.

Code: Select all

<?PHP
$needs_cleaning = "<li><ul></ul></li>" ;
$cleaned = str_replace($needs_cleaning,  "<ul></ul>","") ;
 
print $cleaned ;
?>

Re: Removing unwanted tags

Posted: Mon Mar 24, 2008 10:48 am
by Reviresco

Code: Select all

 
<?PHP
$needs_cleaning = "<li><ul></ul></li>" ;
$cleaned = str_replace("<ul></ul>",  "", $needs_cleaning ) ;
print $cleaned ;
?>
 

Code: Select all

 
$needs_cleaning = "<li><ul></ul></li>" ;
$cleaned = strip_tags($needs_cleaning, '<li>');
 

Re: Removing unwanted tags

Posted: Mon Mar 24, 2008 1:41 pm
by Addos
Okay let me explain more. The code below has 2 unwanted <ul></ul> tags and I want to pass this through the strip_tag function (on something similar) that will remove these if found together however I need the <ul></ul> tags elsewhere in the script so I just want to remove only those that appear side by side. Is this possible?
Thanks for the reply

Re: Removing unwanted tags

Posted: Mon Mar 24, 2008 3:54 pm
by Reviresco
You'll need to use the str_replace because the strip_tags will take out all of the <ul> tags.