Results 1 to 6 of 6

Thread: [RESOLVED] search replace help

  1. #1

    Thread Starter
    Addicted Member kzatu's Avatar
    Join Date
    Aug 2003
    Location
    Nevada
    Posts
    148

    Resolved [RESOLVED] search replace help

    I am trying to remove specific HTML tags from from text. I am currently working with the str_ireplace but it is starting to get cumbersome because there are so many ways to write the same tag. This is what I have now
    PHP Code:
    $search=array('<p>','</p>','</ p>','<p/>','<p />','<br>','</br>','</ br>','<br/>','<br />');
    $replace=array('','','','','','','','','',''); 
    and that is only two of the tags I want to remove. By the time I am done this line will be a mile long.

    I tried reading the pattern rules to preg_replace but something unexpected happened, my head detached from my neck and hit the floor.

    There must be a simpler way. (using a case-insensitive function is a bonus )
    Changes are not permanent, but change is. {Neil Peart}

  2. #2
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: search replace help

    You would have to use regular expressions.

    http://www.regular-expressions.info/php.html

    I suck with regex so I wont be much help on the subject I'm afraid.

    Also, if there is XML in the code, it could cause issues as well.

  3. #3
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: search replace help

    Use the strip_tags function. You can pass an array of tags to allow and the rest will be removed.
    Last edited by penagate; Feb 6th, 2008 at 09:36 PM.

  4. #4
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: search replace help

    I had no idea that function existed, but you linked incorrectly pena.

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

  5. #5
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: search replace help

    Thanks, I fixed the link.

  6. #6

    Thread Starter
    Addicted Member kzatu's Avatar
    Join Date
    Aug 2003
    Location
    Nevada
    Posts
    148

    Re: search replace help

    Works like a charm. Thanks penagate. This is why I love PHP. It seems that they have a function for everything.
    Changes are not permanent, but change is. {Neil Peart}

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width