strip selected tags working, string replacement not

Discussion in 'PHP' started by Luke Jones, Jul 20, 2007.

  1. #1
    Hello,
    Please could you tell me why, in the following code, the strip_selected_tags function is working perfectly, but the _replacement($text) is not:
    function strip_selected_tags($str, $tags = "", $stripContent = false){
            preg_match_all("/<([^>]+)>/i",$tags,$allTags,PREG_PATTERN_ORDER);
            foreach ($allTags[1] as $tag){
                if ($stripContent) {
                    $str = preg_replace("/<".$tag."[^>]*>.*<\/".$tag.">/iU","",$str);
                }
                $str = preg_replace("/<\/?".$tag."[^>]*>/iU","",$str);
            }
            return $str;
        }
    function _replacement($text) {
    $array = array("sabbatical" => "removed", "Wood" => "Tree", "Reporter" => "Journalist");
    foreach($array as $original => $replacement) {
    $text = str_replace($original, $replacement, $text);
    }
    return $text;
    }
    foreach($wsql->fetch_objects() as $obj){
    
       print _replacement($text);
       print strip_selected_tags($obj->text, '<a><img>');
    
        }
    
    PHP:
    I would greatly appreciate any help.
    Thanks
     
    Luke Jones, Jul 20, 2007 IP
  2. Luke Jones

    Luke Jones Peon

    Messages:
    427
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    If I change the print _replacement($text); to:
    print _replacement($obj->text, $text);
    the replacement works, but the tag strip does not. It's one or the other. How do I make both work together?
     
    Luke Jones, Jul 20, 2007 IP
  3. Luke Jones

    Luke Jones Peon

    Messages:
    427
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Can anyone help me with this?
     
    Luke Jones, Jul 20, 2007 IP