+ -
当前位置:首页 → 问答吧 → 分享俩小函数

分享俩小函数

时间:2011-07-11

来源:互联网

  1. /**
  2. +----------------------------------------------------------
  3. * 遍历目录,输出树状结构数组
  4. +----------------------------------------------------------
  5. * @param string $path 目录路径
  6. +----------------------------------------------------------
  7. * @return array
  8. +----------------------------------------------------------
  9. */
  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. }
复制代码

作者: mycn   发布时间: 2011-07-11

顶你

作者: jsf   发布时间: 2011-07-12