本文實(shí)例講述了php獲取網(wǎng)站百度快照日期的方法。分享給大家供大家參考。具體如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
<html> <head> <title>在線演示_php獲取某網(wǎng)站的快照時間</title> <meta http-equiv= "Content-Type" content= "text/html; charset=utf-8" /> <meta name= "keywords" content= "百度,baidu,查詢快照結(jié)果" > <meta name= "description" content= "php查詢網(wǎng)站快照日期: " > </head> <body> <?php $k =isset( $_POST [ 'k' ])? $_POST [ 'k' ]: '' ; ?> <form method= "post" action= "" > <h2>查詢網(wǎng)站快照日期:</h2> 輸入網(wǎng)址:<br /> http: //<input type="text" name="k" size="60" value="<?php echo $k ?>"> <input type= "submit" value= "提交" > </form> <?php /* php獲取某網(wǎng)站的快照時間 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程序設(shè)計(jì)有所幫助。