strip_tags() … replace tags by space rather than deleting them

前端 未结 10 971
日久生厌
日久生厌 2020-12-08 06:36

Do you know how to replace html tags with a space character using php?

If I display

strip_tags(\'

Foo

bar\');

10条回答
  •  春和景丽
    2020-12-08 07:16

    You can try

    $str = '

    Foo

    bar'; var_dump(replaceTag($str,array("h1"=>"div")));

    Output

    string '
    Foo
    bar' (length=17)

    Function Used

    function replaceTag($str,$tags) {
        foreach ( $tags as $old => $new )
            $str = preg_replace("~<(/)?$old>~", "<\\1$new>", $str);
        return $str;
    }
    

提交回复
热议问题