使用Dom Crawler只获取文本(没有标记).
- $html = EOT<<<
- <div class="coucu">
- Get Description <span>Coucu</span>
- </div>
- EOT;
- $crawler = new Crawler($html);
- $crawler = $crawler->filter('.coucu')->first()->text();
更新:
- ...
- $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]);