dom - How do I grab a particular class id from HTML in PHP -
i have html file this.
<html> <body> ..... ..... <p class="new"> text <a href>link </a> </p> <p class="new"> more text here. </p> <p class="new"> more text here. </p> </body> </html>
i want text below:
this text link. more text here. more text here. how approach. tried
$xpath = new domxpath($doc); $nodes = $xpath->query('//p[contains(@class,'new')]');
no success.
error: syntax error, unexpected t_string
you're using single quotes create string that's used argument query
method , embed in string class name. need escape within quotes or switch single double quotes. seek this:
$nodes = $xpathsearch->query('//p[contains(@class,"new")]');
or this:
$nodes = $xpathsearch->query('//p[contains(@class,\'new\')]');
see here php's notes on using single or double quotes , escaping values within quotes.
html dom domdocument php
No comments:
Post a Comment