I find and save every object inside t" />

I find and save every object inside t" />

I find and save every object inside t"/>

PHP Domxpath How to get plain text that not inside a tag in an object

129 views Asked by At

So, I have an HTML like this.

<p> 
  Example Text 1
  <span> Text </span>
  Example Text 2
  <img src="example.png">
</p>

I find and save every object inside that p tag like this.

$subObjects = $xpath->evaluate("*", $object);

But I want to get also "Example Text 1" and "Example Text 2" in order like tags. How can I get these plain texts like a tag via using PHP DomXPATH? Thanks in advance.

1

There are 1 answers

0
Rob Ruchte On BEST ANSWER

You need to add the text() function to your XPath query:

$subObjects = $xpath->evaluate("*|text()", $object);