我是下面的函数,我在努力输出DOMDocument而没有在内容输出之前附加XML,HTML,body和p标签包装器.建议的修复:
$postarray['post_content'] = $d->saveXML($d->getElementsByTagName('p')->item(0));
仅在内容中没有块级元素时才有效.但是,当它执行时,如下面的例子中的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 = …我想要做的是在PHP系统中包含一个HTML文件(不是问题),但由于各种原因,HTML文件也需要单独使用,所以我需要知道如何剥离doctype,html ,如果可能的话,在PHP的上下文中包含头部和身体标签.
我不是特别擅长PHP(doh!)所以我对php手册和网络的搜索并没有让我想到这一点.意味着任何帮助或阅读提示,或两者,非常感谢.