0

I would like to exclude some elements from DOM to extract a piece of text.

For example, with this code:

<div>foo <b>bar</b></div>

I would like to extract only the text "foo". Is there any way to do it?

Thank you very much in advance.

xavigs1984
  • 90
  • 2
  • 11
  • Pleas add the code you have so far. – Nigel Ren Nov 28 '19 at 10:32
  • You very nearly have an answer in the question title... [SimpleXML Parser](https://www.php.net/manual/en/book.simplexml.php) – CD001 Nov 28 '19 at 10:36
  • The code of the element->innertext is: ``` Torreón ``` I would like to extract the text "Torreón". This code is a div's content. – xavigs1984 Nov 28 '19 at 10:37
  • Possible duplicate of [How do you parse and process HTML/XML in PHP?](https://stackoverflow.com/questions/3577641/how-do-you-parse-and-process-html-xml-in-php) – Clément Nov 28 '19 at 11:07

1 Answers1

1

PHP has built in function strip_tags()

Eugene
  • 1,690
  • 3
  • 16
  • 30