0

I have managed to drill down to the element that I want. Here is an example of the html markup

<p> <strong> Title foo </strong> foo bar foo bar </p>

Is there a way to check if the string of a node contains <strong> or <b> etc? Is there a way to do this with DOMDocument or would I have to implement an xpath solution??

Thanks.

Blender
  • 289,723
  • 53
  • 439
  • 496
JS1986
  • 1,920
  • 4
  • 29
  • 50

2 Answers2

1

Is there a way to check if the string of a node contains or etc

Try looking at the textContent property of the node. Watch out, textContent searches both the node and all descendants. If you need a precise match and don't want to crawl the tree yourself, then a xpath solution would probably be faster.

Charles
  • 50,943
  • 13
  • 104
  • 142
0

You can use a regular expression to check whether the string you are looking for is included in the content of the node.

Rasika
  • 1,980
  • 13
  • 19
  • 1
    [No no no no no. N͍̰̜̯̯ͥ͆͒͠óͯ͗̂ͅ.͚̰̗̬̱͎͋͂̈́̊](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454). – Charles Apr 01 '11 at 05:25