Home > php教程 > php手册 > PHP截取远端网页资讯

PHP截取远端网页资讯

WBOY
Release: 2016-06-13 10:48:57
Original
924 people have browsed it

以下程序代码会介绍如何截取远端网页资讯,包括HTML tag 里面的Title, Description 及Keywords:
 
PLAIN TEXT
PHP:
//—–定义要截取的网页地址
$url = “http:// www.2cto.com ”;
//—– 读取网页原始码
$fp = file_get_contents($url);
//—– 截取title 资讯
preg_match(“/

(.*)/s”, $fp, $match);<br> $title = $match[1];<br> //—– 截取Description 及Keywords<br> $metatag = get_meta_tags($url);<br> $description = $metatag["description"];<br> $keywords = $metatag["keywords"];<br> //—– 印出結果<br> echo “URL: $url\n”;<br> echo “Title: $title\n”;<br> echo “Description: $description\n”;<br> echo “Keywords: $keywords\n”;<br> ?>
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template