Retrieving some tags from a string parsed by htmlentities

Discussion in 'PHP' started by clades, Oct 13, 2008.

  1. #1
    I have a string already parsed by htmlentities function.

    I need to be able to reverse the htmlentities function only for a certain tags.

    Anyone knows how can i do it?

    For example:

    filtertag('<b>')

    to

    &lt;a href=&quot;http://www.asdasd.com&quot;&gt;Link&lt;/a&gt;
    &lt;br&gt;&lt;br&gt;&lt;b&gt;My bold text&lt;/b&gt;
    HTML:
    Gives

    &lt;a href=&quot;http://www.asdasdasd.com&quot;&gt;Link&lt;/a&gt;
    &lt;br&gt;&lt;br&gt;<b>My bold text</b>
    HTML:
    The function must be able to deal with any tag and reverse it.
     
    clades, Oct 13, 2008 IP
  2. geforce

    geforce Active Member

    Messages:
    173
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    78
    #2
    Make an array of tags you want to reverse, such as:

    
    function filtertag( $string ) {
    
    $good_tags = array('&lt;b&gt;' => "<b>", '&lt;/b&gt;' => "</b>");
    
    foreach($good_tags as $start => $end) {
    
     str_replace($start, $end, $string);
    
    }
    
    return $string;
    }
    
    
    PHP:
    Hope that helps.
     
    geforce, Oct 13, 2008 IP
  3. clades

    clades Peon

    Messages:
    579
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #3
    What if the tag works in a different way?
    For example img may be <img src="" class="x" alt=""...>

    The tag list is not fixed...its a variable that comes from admin settings.
     
    clades, Oct 13, 2008 IP