删除 class 和 h1 的样式 simple_html_dom 结果

Remove class and styling of h1 with simple_html_dom results

以下是我的代码:

$html = $_GET['html'];
$dom = file_get_html($html);
$h1 = $dom->find('h1');
echo $h1[0];

它 returns H1 文本,但与 class 最初相关联。喜欢:

<h1 class="postpageheading">the returned text </h1>

我只想要文字,连标签都不要。

我该怎么做? 谢谢

尝试:

echo $h1[0]->plaintext;

从您的 file_get_html 方法看来,您正在使用 PHP 简单 HTML DOM 解析器。

如果您在这里查看他们的快速入门:

http://simplehtmldom.sourceforge.net/

单击选项卡 "Extract contents from HTML",它显示了如何使用此 plaintext 获取没有标签的内容。

您可以 运行 对您的结果使用正则表达式,例如:

$result = preg_replace("/[^A-Z]+/", "", $string);

strip_tags 如下所述:http://php.net/strip_tags