php - Xpath query not working -


here html:

<div class="blogentry expecting featured featured-post-today%e2%80%99s-top-story first"> <h2><a href="/2013/09/03/rachel-zoe-pregnant-expecting-second-child/" rel="bookmark" title="permanent link rachel zoe expecting second&nbsp;child">rachel zoe expecting second&nbsp;child</a></h2> </div> <div class="blogentry expecting featured featured-post-today%e2%80%99s-top-story first"> <h2><a href="someurl" rel="bookmark" title="permanent link rachel zoe expecting second&nbsp;child">sometitle</a></h2> </div> 

i'm trying anchor value. here xpath:

$finder->query('//div[@class="blogentry"]//h2//a'); 

it's returning no value. idea why?

you need use function contains() here:

$xml = <<<eof <div class="blogentry expecting featured featured-post-today%e2%80%99s-top-story first"> <h2><a href="/2013/09/03/rachel-zoe-pregnant-expecting-second-child/" rel="bookmark" title="permanent link rachel zoe expecting second&nbsp;child">rachel zoe expecting second&nbsp;child</a></h2> </div> eof;  $doc = new domdocument(); $doc->loadhtml($xml);  $selector = new domxpath($doc);  foreach($selector->query('//div[contains(@class,"blogentry")]/h2/a/text()') $item) {     echo $item->nodevalue . php_eol; } 

output:

rachel zoe expecting second child 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -