分享俩小函数
thinkphp吧
全部回复
仅看楼主
level 1
yxn1910 楼主
01./**
02.+----------------------------------------------------------
03.* 遍历目录,输出树状结构数组
04.+----------------------------------------------------------
05.* @param string $path 目录路径
06.+----------------------------------------------------------
07.* @return array
08.+----------------------------------------------------------
09.*/
10.function foreachDir($path){
11.foreach (scandir($path) as $file){
12.if(in_array($file,array('.','..'))) continue;
13.$fullPath = $path.'/'.$file;
14.if(is_dir($fullPath)){
15.$result[$file] = foreachDir($fullPath);
16.}else{
17.$temp[]=$file;
18.}
19.}
20.foreach ($temp as $key){
21.$result[]=$key;
22.}
23.return $result;
24.}
25./**
26.+----------------------------------------------------------
27.* 返回对应搜索引擎蜘蛛
28.+----------------------------------------------------------
29.* @return string
30.+----------------------------------------------------------
31.*/
32.function spider(){
33.$agent = $_SERVER['HTTP_USER_AGENT'];
34.if(strpos($agent,'Baiduspider')){
35.$ip = get_client_ip();
36.if(strpos(`host $ip`,'baiduspider')){
37.return 'Baidu';
38.}
39.}
40.if(strpos($agent,'Googlebot')) return 'Google';
41.if(strpos($agent,'Sosospider')) return 'Soso';
42.if(strpos($agent,'Sogou')) return 'Sogou';
43.return false;
44.}
复制代码

2011年07月28日 14点07分 1
level 5
40.if(strpos($agent,'Googlebot')) return 'Google';
41.if(strpos($agent,'Sosospider')) return 'Soso';
42.if(strpos($agent,'Sogou')) return 'Sogou';
43.return false;
44.}
复制代码
2011年09月21日 09点09分 2
level 5
先弄下来试试顶不顶用在看。
2011年09月21日 09点09分 3
level 5
果然是个实用的好函数,顶一个。
2011年09月21日 09点09分 5
1