php domdocument读取元素内部文本 [英] php domdocument read element inner text
本文介绍了php domdocument读取元素内部文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是php的新手,请原谅一个简单的问题:
I'm new to php so please forgive the simple question:
如何从元素中提取文本?
How do I extract the text from an element?
<span id="myElement">Some text I want to read</span>
我有一个开始:
<?php
$data = $dom->getElementById("myElement");
$html = $dom->saveHTML($data);
然后呢?正确的指示是什么?
But then? What is the correct instruction?
推荐答案
要获取元素包含的文本,您需要textContent
属性:
To get the text that an element contains, you need the textContent
property:
$text = $data->textContent;
这篇关于php domdocument读取元素内部文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文