The internal text of the php domdocument read element

I am new to php, so please forgive the simple question:

How to extract text from an element?

<span id="myElement">Some text I want to read</span> 

I have this for starters:

 <?php $data = $dom->getElementById("myElement"); $html = $dom->saveHTML($data); 

But then? What is the correct instruction?

+4
source share
1 answer

To get the text that contains the element, you need the textContent property:

 $text = $data->textContent; 
+13
source

Source: https://habr.com/ru/post/1485703/


All Articles