How Can i get the child element using class using php DOMXPath? -



How Can i get the child element using class using php DOMXPath? -

i want kid element specific class form html have manage find element using tag name can't figureout how can kid emlement specific class?

here code:

<?php $html = file_get_contents('myfileurl'); //get html returned next url $pokemon_doc = new domdocument(); libxml_use_internal_errors(true); //disable libxml errors if (!empty($html)) { //if html returned $pokemon_doc->loadhtml($html); libxml_clear_errors(); //remove errors yucky html $pokemon_xpath = new domxpath($pokemon_doc); //get h2's id $pokemon_row = $pokemon_xpath->query("//li[@class='content']"); if ($pokemon_row->length > 0) { foreach ($pokemon_row $row) { $title = $row->getelementsbytagname('h3'); foreach ($title $a) { echo "title: "; echo strip_tags($a->nodevalue). '<br>'; } $links = $row->getelementsbytagname('a'); foreach ($links $l) { echo "link: "; echo strip_tags($l->nodevalue). '<br>'; } $desc = $row->getelementsbytagname('span'); //i tried didnt work..... iwant span class desc //$desc = $row->query("//span[@class='desc']"); foreach ($desc $d) { echo "desc: "; echo strip_tags($d->nodevalue) . '<br><br>'; } // echo $row->nodevalue . "<br/>"; } } } ?>

please allow me know if duplicate cant find out or think question not or not explaining please allow me know in comments.

thanks.

php

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -