php - How can I query my HTML using this jQuery expression? -
i'm processing html , need query particular subset of it, know how jquery selectors.
here's php code:
$words = array('word'); $baseurl = 'http://lema.rae.es/drae/srv/search?val='; //word goes @ end $resultindex = 0; foreach($words $word) { if (!isset($_request[$word])) continue; $contents = file_get_contents($baseurl . urldecode(utf8_decode($_request[$word]))); // doesn't work! how write in php $dataineed = $contents.find(".ul a").attr("href"); $contents = preg_replace('/(search?[\d\w]+)/','http://lema.rae.es/drae/srv/', $contents); echo "<div id='results' style=' //style ", (++$resultindex) ,"'>", $dataineed, $contents, "</div>"; }
the query use in jquery this:
.find(".ul a").attr("href")
how can write using php , dom?
using xpath:
$doc = new domdocument(); $doc->loadhtml($contents); $xp = new domxpath($doc); $dataineed = $xp->query('//*[contains(concat(" ",@class," ")," ul ")]//a') ->item(0) ->getattribute('href');
Comments
Post a Comment