現(xiàn)在我們所取回的文件已經(jīng)存放在數(shù)組$num_searched中。現(xiàn)在要在數(shù)組中查找我們想要的文本"about (.*) pages found. "。(.*)表示在任何東西。而且,如果沒有人鏈接我們的url,altavista將顯示"altavista found no document matching your query."。因?yàn)槲覀兿胫蓝嗌賯€(gè)人正在與我們的url進(jìn)行著鏈接,那段文本將被看 作0個(gè)人鏈接。
about (.*) pages found.", "1", $num_searched[$i]); } elseif(eregi( "altavista found no document matching your query.",$num_searched[$i])){ $total_links = "0"; } }
這樣,我們可以通過打印語句得到我們的查找結(jié)果了: print("$total_links people are linking to $url");
create table ccol( id integer not null auto_increment, #記錄的id ip char(15) not null, #訪問者的ip地址 dtstamp datetime not null, #最后訪問時(shí)間 uri char(255), #訪問者請求的uri primary key (id) );
$duration=1800; require "db.php"; //包含dbsql,詳情可以參考我的另一篇文章 $ccol=new dbsql; $ccol->connect(); $ccol->query("delete from ccol where (unix_timestamp(now())-unix_timestamp(dtstamp))>$duration"); //刪除超過半小時(shí)的記錄 $ccol->query("select * from ccol where ip="$remote_addr""); //判斷當(dāng)前的ip是否在該表中存在 if ($ccol->nf())//有? { $ccol->next_record();//下移找到的記錄數(shù)組的指針 $id=$ccol->f("id"); $ccol->query("update ccol set dtstamp=now(), uri="$request_uri" where id=$id"); //設(shè)置最后訪問時(shí)間和訪問頁面 } else//沒有 { $ccol->query("insert into ccol values (0, "$remote_addr", now(), "$request_uri")"); }
$ccol->query("select count(*) as ccol from ccol where (unix_timestamp(now())-unix_timestamp(dtstamp))<=$duration"); //找出在半個(gè)小時(shí)內(nèi)的記錄,后面的where子句可有可無--超出時(shí)間的已經(jīng)被刪除了 $ccol->next_record() echo "在線人數(shù):", $ccol->f("ccol"); $ccol->free_result();