PHP截取远端网页资讯_PHP教程
时间:2021-07-01 10:21:17
帮助过:12人阅读
以下程序代码会介绍如何截取远端网页资讯,包括HTML tag 里面的Title, Description 及Keywords:
PLAIN TEXT
PHP:
//—–定义要截取的网页地址
$url = “http:// www.2cto.com ”;
//—– 读取网页原始码
$fp = file_get_contents($url);
//—– 截取title 资讯
preg_match(“/
(.*)<\/title>/s”, $fp, $match);
$title = $match[1];
//—– 截取Description 及Keywords
$metatag = get_meta_tags($url);
$description = $metatag["description"];
$keywords = $metatag["keywords"];
//—– 印出結果
echo “URL: $url\n”;
echo “Title: $title\n”;
echo “Description: $description\n”;
echo “Keywords: $keywords\n”;
?>
http://www.bkjia.com/PHPjc/478263.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/478263.htmlTechArticle以下程序代码会介绍如何截取远端网页资讯,包括HTML tag 里面的Title, Description 及Keywords: PLAIN TEXT PHP: ?php //定义要截取的网页地址 $url = ht...