代码如下,只为方括号转义,如果直接使用 htmlentities 函数则会将所有字符转换为 HTML 实体
function pre_content_filter( $content ) {
return preg_replace_callback('|<pre.*><code.*>(.*)</code></pre|isU', 'convert_pre_entities', $content );
}
function convert_pre_entities( $matches ) {
return str_replace( $matches[1], FunctionName( $matches[1] ), $matches[0] );
}
function FunctionName($value='')
{
$value = str_replace("<", "<", $value);
$value = str_replace(">", ">", $value);
return $value;
}