亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

php用xpath解析html的代碼實(shí)例講解

 更新時(shí)間:2019年02月14日 14:44:34   投稿:laozhang  
在本篇文章里小編給大家分享了關(guān)于php用xpath解析html的代碼實(shí)例講解,對(duì)此有需要的朋友們可以學(xué)習(xí)下。

實(shí)例1

$xml = simplexml_load_file('https://forums.eveonline.com'); 
 
$names = $xml->xpath("html/body/p/p/form/p/p/p/p/p[*]/p/p/table//tr/td[@class='topicViews']"); 
foreach($names as $name) 
{ 
 echo $name . "<br/>"; 
}

實(shí)例2

$url = 'http://www.baidu.com';
$ch = curl_init();
curl_setopt($ch, CURLOPT_FILE, fopen('php://stdout', 'w'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_URL, $url);
$html = curl_exec($ch); 
curl_close($ch);
 
// create document object model
$dom = new DOMDocument();
// load html into document object model
@$dom->loadHTML($html);
// create domxpath instance
$xPath = new DOMXPath($dom);
// get all elements with a particular id and then loop through and print the href attribute
$elements = $xPath->query('//*[@id="lg"]/img/@src');
foreach ($elements as $e) {
 echo ($e->nodeValue);
}

以上就是相關(guān)的2個(gè)實(shí)例內(nèi)容,以及相關(guān)的代碼, 感謝大家對(duì)腳本之家的支持。

相關(guān)文章

最新評(píng)論