【发布时间】:2016-10-31 13:00:09
【问题描述】:
我是 php 新手。我正在尝试使用 php 从 html 中提取整个 body 标记。
这里是我的示例 html:
<html>
<body >
<p>
Example html content
</p>
</body>
</html>
我只想从 html 内容中提取以下内容:
<p>
Example html content
</p>
使用以下我尝试解决,但它只输出没有 html 标签的字符串:
$dom = new domDocument;
$dom->loadHTML("<html><body><p>Example html content</p></body></html>");
$body = $dom->getElementsByTagName('body')->item(0);
var_dump($body->textContent); //output:Example html content
请帮我解决这个问题。
【问题讨论】:
-
使用
$dom->saveHTML($body)
标签: javascript php jquery html