最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

php用xpath解析html的代碼實例講解

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

實例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/>"; 
}

實例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個實例內(nèi)容,以及相關(guān)的代碼, 感謝大家對腳本之家的支持。

相關(guān)文章

最新評論

吐鲁番市| 广宁县| 墨竹工卡县| 渭源县| 安图县| 汉阴县| 临漳县| 吉林市| 铜陵市| 郎溪县| 祁门县| 漯河市| 南召县| 郑州市| 奉贤区| 九台市| 孙吴县| 深州市| 大丰市| 鹿泉市| 武鸣县| 大庆市| 明水县| 谷城县| 兴安县| 商南县| 南京市| 恩施市| 吉安市| 拉孜县| 巴林左旗| 介休市| 丹东市| 民权县| 延长县| 泰和县| 江永县| 中卫市| 新河县| 大庆市| 荥阳市|