文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>网站当前在线人数的实现

网站当前在线人数的实现

时间:2007-02-17  来源:PHP爱好者

译者:limodou
www.c hinaitpower.comlHzHoqC6SwSjHlEo2cZPggdaGr

www.c hinaitpower.comlHzHoqC6SwSjHlEo2cZPggdaGr
  一个网站最重要的组成部分可能就是与你链接的站点的个数。这个教程将向你显示一个使用AltaVista
www.c hinaitpower.comlHzHoqC6SwSjHlEo2cZPggdaGr
搜索引擎来实现的简单方法。
www.c hinaitpower.comlHzHoqC6SwSjHlEo2cZPggdaGr

www.c hinaitpower.comlHzHoqC6SwSjHlEo2cZPggdaGr
  首先,我们需要准备在脚本中使用的URL 。这个可以使用:
www.c hinaitpower.comlHzHoqC6SwSjHlEo2cZPggdaGr

www.c hinaitpower.comlHzHoqC6SwSjHlEo2cZPggdaGr
http://www.altavista.com/cgi-bin/query?kl=XX&pg=q&text=yes&q=link%3A<待查的URL>&search=Search。
www.c hinaitpower.comlHzHoqC6SwSjHlEo2cZPggdaGr

www.c hinaitpower.comlHzHoqC6SwSjHlEo2cZPggdaGr
  应该知道这是AltaVista的一个文本版本。这样可以节省我们大量的需要解析HTML的代码。接着,我们
www.c hinaitpower.comlHzHoqC6SwSjHlEo2cZPggdaGr
需要确切的URL。我们应该使用rawurlencode()来处理URL保证Altavista能够正确地处理它。
www.c hinaitpower.comlHzHoqC6SwSjHlEo2cZPggdaGr

www.c hinaitpower.comlHzHoqC6SwSjHlEo2cZPggdaGr

www.c hinaitpower.comlHzHoqC6SwSjHlEo2cZPggdaGr
$url = 'http://www.php.net';
www.c hinaitpower.comlHzHoqC6SwSjHlEo2cZPggdaGr

www.c hinaitpower.comlHzHoqC6SwSjHlEo2cZPggdaGr
$url_encoded = rawurlencode($url);
www.c hinaitpower.comlHzHoqC6SwSjHlEo2cZPggdaGr

www.c hinaitpower.comlHzHoqC6SwSjHlEo2cZPggdaGr
$url_to_check = "http://www.altavista.com/cgi-bin/query?
www.c hinaitpower.comlHzHoqC6SwSjHlEo2cZPggdaGr
kl=XX&pg=q&text=yes&q=link%3A$url_encoded&search=Search";
www.c hinaitpower.comlHzHoqC6SwSjHlEo2cZPggdaGr
?>
www.c hinaitpower.comlHzHoqC6SwSjHlEo2cZPggdaGr
  现在我们有了我们需要的全部的URL 。到了我们抓回URL 的时候了。这步工作是通过使用file()函数。
www.c hinaitpower.comlHzHoqC6SwSjHlEo2cZPggdaGr

www.c hinaitpower.comlHzHoqC6SwSjHlEo2cZPggdaGr
$url = 'http://www.php.net';
www.c hinaitpower.comlHzHoqC6SwSjHlEo2cZPggdaGr

www.c hinaitpower.comlHzHoqC6SwSjHlEo2cZPggdaGr
$url_encoded = rawurlencode($url);
www.c hinaitpower.comlHzHoqC6SwSjHlEo2cZPggdaGr

www.c hinaitpower.comlHzHoqC6SwSjHlEo2cZPggdaGr
$url_to_check = "http://www.altavista.com/cgi-bin/query?
www.c hinaitpower.comlHzHoqC6SwSjHlEo2cZPggdaGr
kl=XX&pg=q&text=yes&q=link%3A$url_encoded&search=Search";
www.c hinaitpower.comlHzHoqC6SwSjHlEo2cZPggdaGr

www.c hinaitpower.comlHzHoqC6SwSjHlEo2cZPggdaGr
$alta_search = file($url_to_check);
www.c hinaitpower.comlHzHoqC6SwSjHlEo2cZPggdaGr
?>
www.c hinaitpower.comlHzHoqC6SwSjHlEo2cZPggdaGr
  现在我们所抓回的文件已经存放在数组$alta_search中。我们现在要在数组中查找我们想要的文本。我
www.c hinaitpower.comlHzHoqC6SwSjHlEo2cZPggdaGr
们想要的文本就是"About (.*) pages found. "。(.*)表示在两个单词之间的任何东西。而且,如果没有人
www.c hinaitpower.comlHzHoqC6SwSjHlEo2cZPggdaGr
链接我们的URL,AltaVista将显示"AltaVista found no document matching your query."。因为我们想知
www.c hinaitpower.comlHzHoqC6SwSjHlEo2cZPggdaGr
道多少个人正在与我们的URL进行着链接,那段文本将被看作0个人链接。
www.c hinaitpower.comlHzHoqC6SwSjHlEo2cZPggdaGr

www.c hinaitpower.comlHzHoqC6SwSjHlEo2cZPggdaGr
$url = 'http://www.php.net';
www.c hinaitpower.comlHzHoqC6SwSjHlEo2cZPggdaGr

www.c hinaitpower.comlHzHoqC6SwSjHlEo2cZPggdaGr
$url_encoded = rawurlencode($url);
www.c hinaitpower.comlHzHoqC6SwSjHlEo2cZPggdaGr

www.c hinaitpower.comlHzHoqC6SwSjHlEo2cZPggdaGr
$url_to_check =
www.c hinaitpower.comlHzHoqC6SwSjHlEo2cZPggdaGr
"http://www.altavista.com/cgi-bin/query?kl=XX&pg=q&text=yes&q=link%3A$url_encoded&search=Search";
www.c hinaitpower.comlHzHoqC6SwSjHlEo2cZPggdaGr

www.c hinaitpower.comlHzHoqC6SwSjHlEo2cZPggdaGr
$alta_search = file($url_to_check);
www.c hinaitpower.comlHzHoqC6SwSjHlEo2cZPggdaGr

www.c hinaitpower.comlHzHoqC6SwSjHlEo2cZPggdaGr
for ($i = 0; $i <count($alta_search); $i++) {
www.c hinaitpower.comlHzHoqC6SwSjHlEo2cZPggdaGr
if(eregi( "About (.*) pages found.", $alta_search[$i])){
www.c hinaitpower.comlHzHoqC6SwSjHlEo2cZPggdaGr
$how_many = eregi_replace( "
www.c hinaitpower.comlHzHoqC6SwSjHlEo2cZPggdaGr
About (.*) pages found.", "1", $alta_search
www.c hinaitpower.comlHzHoqC6SwSjHlEo2cZPggdaGr
[$i]);
www.c hinaitpower.comlHzHoqC6SwSjHlEo2cZPggdaGr
}elseif(eregi( "AltaVista found no document matching your query.", $alta_search
www.c hinaitpower.comlHzHoqC6SwSjHlEo2cZPggdaGr
[$i])){
www.c hinaitpower.comlHzHoqC6SwSjHlEo2cZPggdaGr
$how_many = '0';
www.c hinaitpower.comlHzHoqC6SwSjHlEo2cZPggdaGr
}
www.c hinaitpower.comlHzHoqC6SwSjHlEo2cZPggdaGr
}
www.c hinaitpower.comlHzHoqC6SwSjHlEo2cZPggdaGr

www.c hinaitpower.comlHzHoqC6SwSjHlEo2cZPggdaGr
?>
www.c hinaitpower.comlHzHoqC6SwSjHlEo2cZPggdaG
php爱好者站 http://www.phpfans.net 为phper提供一切资讯.
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载