<html>
<head>
<title>PHP獲取某網站的百度快照日期方法 http://</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="百度,baidu,查詢快照結果">
<meta name="description" content="php查詢網站快照日期: by enenba.com">
</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獲取某網站的快照時間
2016-1-30
@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>
*