Okay, let’s say I have this string:
<div class='box'>i like the world</div><div class='box'>i like my computer</div>
How would I go about echoing the divs that contain the word “world”?
Would this envolve some sort of regex?
Thank you so much in advance.
Using DOMDocument and DOMXPath you can easily do this:
Now
$nodescontain all thedivelements which contain the wordworld.Demo: http://codepad.viper-7.com/Dhalvh
Please note that you don’t want to try to parse HTML with regex, because it’s a matter of when and not if it is going to break.