How to use php preg_replace to replace HTML tags

前端 未结 3 1445
执念已碎
执念已碎 2020-12-17 04:11

I\'d like to change

 with  and 
with .

I\'m having problem with t

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-17 04:27

    You could just use str_replace:

    $str = str_replace(array('
    ', '
    '), array('', ''), $str);

    If you feel compelled to use regexp:

    $str = preg_replace("~<(/)?pre>~", "<\\1code>", $str);
    

    If you want to replace them separately:

    $str = preg_replace("~
    ~", '', $str);
    $str = preg_replace("~
    ~", '', $str);

    You just need to escape that slash.

提交回复
热议问题