以下程序代碼會介紹如何截取遠端網頁資訊,包括HTML tag 裡面的Title, Description 及Keywords:
PLAIN TEXT
PHP:
<?php
//—–定義要截取的網頁地址
$url = “http:// www.2cto.com ”;
//—– 讀取網頁原始碼
$fp = file_get_contents($url);
//—– 截取title 資訊
preg_match(“/<title>(.*)<\/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”;
?>