相关疑难解决方法(0)

如何在没有HTML包装器的情况下保存DOMDocument的HTML?

我是下面的函数,我在努力输出DOMDocument而没有在内容输出之前附加XML,HTML,bodyp标签包装器.建议的修复:

$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)

php serialization domdocument

106
推荐指数
9
解决办法
5万
查看次数

获取没有DOCTYPE,HTML,HEAD和BODY标签的BODY内容

我想要做的是在PHP系统中包含一个HTML文件(不是问题),但由于各种原因,HTML文件也需要单独使用,所以我需要知道如何剥离doctype,html ,如果可能的话,在PHP的上下文中包含头部和身体标签.

我不是特别擅长PHP(doh!)所以我对php手册和网络的搜索并没有让我想到这一点.意味着任何帮助或阅读提示,或两者,非常感谢.

php

15
推荐指数
4
解决办法
2万
查看次数

标签 统计

php ×2

domdocument ×1

serialization ×1