我是下面的函数,我在努力输出DOMDocument而没有在内容输出之前附加XML,HTML,body和p标签包装器.建议的修复:
$postarray['post_content'] = $d->saveXML($d->getElementsByTagName('p')->item(0));
Run Code Online (Sandbox Code Playgroud)
仅在内容中没有块级元素时才有效.但是,当它执行时,如下面的例子中的h1元素,saveXML的结果输出被截断为...
<p>如果你喜欢</ p>
我已经指出这篇文章可能是一种解决方法,但是我无法理解如何将它实现到这个解决方案中(参见下面的注释).
有什么建议?
function rseo_decorate_keyword($postarray) {
global $post;
$keyword = "Jasmine Tea"
$content = "If you like <h1>jasmine tea</h1> you will really like it with Jasmine Tea flavors. This is the last ocurrence of the phrase jasmine tea within the content. If there are other instances of the keyword jasmine tea within the text what happens to jasmine tea."
$d = new DOMDocument();
@$d->loadHTML($content);
$x = new DOMXpath($d);
$count = …Run Code Online (Sandbox Code Playgroud)