PHP convert string to htmlentities

前端 未结 4 1247
北恋
北恋 2020-12-22 11:44

How can I convert the code inside the and

 tags to html entities ?

 
a
4条回答
  •  别那么骄傲
    2020-12-22 12:01

    PHP

    if(preg_match_all('#\<(code|pre) class\=\"php\"\>(.*?)\#is', $html, $code)){
        unset($code[0]);
        foreach($code as $array){
            foreach($array as $value){
                $html = str_replace($value, htmlentities($value, ENT_QUOTES), $html);
            }
        }
    }
    

    HTML

     <div> a div.. </div> 
    
    
    <div> a div.. </div>
    
    this should be ignored

    Have you ever heard of BB code? http://en.wikipedia.org/wiki/BBCode

提交回复
热议问题