此函数的目的是简单地将第一次出现的关键字包装为粗体标记。我在下面标记的行上发现一个错误。
警告:DOMDocument::loadHTML()[DOMDocument.loadHTML]:在C:\\xamplite\\htdocs\\testsite\\wp content\\plugins\\mylugin\\test中的第4行分析实体中的属性名称时出错。php在线40
这是传递post\\u内容对象的正确方法吗?
add_filter(\'wp_insert_post_data\', \'my_bold_keyword\' );
function my_bold_keyword($content){
$myKeyword = "test 123";
$d = new DOMDocument();
$d->loadHTML($content[\'post_content\']); //ERROR OCCURS HERE
$x = new DOMXpath($d);
$Matches = $x->query("//text()[contains(.,$myKeyword) and not(ancestor::h1) and not(ancestor::h2) and not(ancestor::h3) and not(ancestor::h4) and not(ancestor::h5) and not(ancestor::h6)]");
if($Matches && $Matches->length > 0){
$myText = $Matches->item(0);
// need to wrap #myText in <b> wrapper
}
return $content;
}