使用 Dom Crawler 仅获取文本(无标签)。
$html = EOT<<<
<div class="coucu">
Get Description <span>Coucu</span>
</div>
EOT;
$crawler = new Crawler($html);
$crawler = $crawler->filter('.coucu')->first()->text();
output:获取说明沙发
我想输出(仅):获取描述
UPDATE:
我找到了一个解决方案:(但这确实是一个糟糕的解决方案)
...
$html = $crawler->filter('.coucu')->html();
// use strip_tags_content in https://php.net/strip_tags
$html = strip_tags_content($html,'span');
遇到同样的情况。我最终选择了:
$html = $crawler->filter('.coucu')->html();
$html = explode("<span", $html);
echo trim($html[0]);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)