本文實例講述了php獲取網站百度快照日期的方法。分享給大家供大家參考。具體如下:
<html>
<head>
<title>在線演示_php獲取某網站的快照時間</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="百度,baidu,查詢快照結果">
<meta name="description" content="php查詢網站快照日期: ">
</head>
<body>
<?php $k=isset($_POST['k'])?$_POST['k']:''; ?>
<form method="post" action="">
<h2>查詢網站快照日期:</h2>
輸入網址:<br />
http://<input type="text" name="k" size="60" value="<?php echo $k ?>">
<input type="submit" value="提交">
</form>
<?php
/*
php獲取某網站的快照時間 by enenba
2012-6-18
@param str $url 一級域名
@param str 時間格式
*/
function getKuaiZhao($text) {
$url = 'http://www.baidu.com/s?word='.$text;
$html = file_get_contents($url);
$text = str_replace('.','/.',addslashes($text));
$search = '/<b>'.$text.'<//b>[^<]*((?:19|20)[0-9]{2}-(?:1[012]|[1-9])-(?:[12][0-9]|3[01]|[1-9]))/';
preg_match($search, $html, $r);
//highlight_string($search);
return $r[1];
}
if($k=='') {
echo('請輸入url');
}else{
if($r = getKuaiZhao($k)) {
echo '快照:'.$r;
}else {
echo('無快照');
}
}
?>
</body>
</html>
希望本文所述對大家的php程序設計有所幫助。
新聞熱點
疑難解答