PHP采集程序中常用的函数

函数描述及例子 PHP采集程序中常用的函数 查询关键字 PHP采集程序中常用的函数

  1. //获得当前的脚本网址   
  2. function get_php_url(){   
  3.         if(!emptyempty($_SERVER["REQUEST_URI"])){   
  4.                 $scriptName = $_SERVER["REQUEST_URI"];   
  5.                 $nowurl = $scriptName;   
  6.         }else{   
  7.                 $scriptName = $_SERVER["PHP_SELF"];   
  8.                 if(emptyempty($_SERVER["QUERY_STRING"])) $nowurl = $scriptName;   
  9.                 else $nowurl = $scriptName."?".$_SERVER["QUERY_STRING"];   
  10.         }   
  11.         return $nowurl;   
  12. }   
  13. //把全角数字转为半角数字   
  14. function GetAlabNum($fnum){   
  15.         $nums = array("0","1","2","3","4","5","6","7","8","9");   
  16.         $fnums = "0123456789";   
  17.         for($i=0;$i<=9;$i++) $fnum = str_replace($nums[$i],$fnums[$i],$fnum);   
  18.         $fnum = ereg_replace("[^0-9.]|^0{1,}","",$fnum);   
  19.         if($fnum==""$fnum=0;   
  20.         return $fnum;   
  21. }   
  22. //去除HTML标记   
  23. function Text2Html($txt){   
  24.         $txt = str_replace("  "," ",$txt);   
  25.         $txt = str_replace("<","<",$txt);   
  26.         $txt = str_replace(">",">",$txt);   
  27.         $txt = preg_replace("/[]{1,}/isU","  
  28. ",$txt);   
  29.         return $txt;   
  30. }  
  31. //清除HTML标记   
  32. function ClearHtml($str){   
  33.         $str = str_replace('<','<',$str);   
  34.         $str = str_replace('>','>',$str);   
  35.         return $str;   
  36. }   
  37. //相对路径转化成绝对路径   
  38. function relative_to_absolute($content$feed_url) {   
  39.     preg_match('/(http|https|ftp):///'$feed_url$protocol);   
  40.     $server_url = preg_replace("/(http|https|ftp|news):///"""$feed_url);   
  41.     $server_url = preg_replace("//.*/"""$server_url);  
  42.     if ($server_url == '') {   
  43.         return $content;   
  44.     }  
  45.     if (isset($protocol[0])) {   
  46.         $new_content = preg_replace('/href="//''href="'.$protocol[0].$server_url.'/'$content);   
  47.         $new_content = preg_replace('/src="//''src="'.$protocol[0].$server_url.'/'$new_content);   
  48.     } else {   
  49.         $new_content = $content;   
  50.     }   
  51.     return $new_content;   
  52. }   
  53. //取得所有链接   
  54. function get_all_url($code){   
  55.         preg_match_all('/<as+href=["|']?([^>"' ]+)["|']?s*[^>]*>([^>]+)</a>/i',$code,$arr);   
  56.         return array('name'=>$arr[2],'url'=>$arr[1]);   
  57. }  
  58. //获取指定标记中的内容   
  59. function get_tag_data($str$start$end){   
  60.         if ( $start == '' || $end == '' ){   
  61.                return;   
  62.         }   
  63.         $str = explode($start$str);   
  64.         $str = explode($end$str[1]);   
  65.         return $str[0];   
  66. }   
  67. //HTML表格的每行转为CSV格式数组   
  68. function get_tr_array($table) {   
  69.         $table = preg_replace("'<td[^>]*?>'si",'"',$table);   
  70.         $table = str_replace("",'",',$table);   
  71.         $table = str_replace("","{tr}",$table);   
  72.         //去掉 HTML 标记   
  73.         $table = preg_replace("'<[/!]*?[^<>]*?>'si","",$table);   
  74.         //去掉空白字符   
  75.         $table = preg_replace("'([])[s]+'","",$table);   
  76.         $table = str_replace(" ","",$table);   
  77.         $table = str_replace(" ","",$table);  
  78.         $table = explode(",{tr}",$table);   
  79.         array_pop($table);   
  80.         return $table;   
  81. }  
  82. //将HTML表格的每行每列转为数组,采集表格数据   
  83. function get_td_array($table) {   
  84.         $table = preg_replace("'<table[^>]*?>'si","",$table);   
  85.         $table = preg_replace("'<tr[^>]*?>'si","",$table);   
  86.         $table = preg_replace("'<td[^>]*?>'si","",$table);   
  87.         $table = str_replace("","{tr}",$table);   
  88.         $table = str_replace("","{td}",$table);   
  89.         //去掉 HTML 标记   
  90.         $table = preg_replace("'<[/!]*?[^<>]*?>'si","",$table);   
  91.         //去掉空白字符   
  92.         $table = preg_replace("'([])[s]+'","",$table);   
  93.         $table = str_replace(" ","",$table);   
  94.         $table = str_replace(" ","",$table);   
  95.           
  96.         $table = explode('{tr}'$table);   
  97.         array_pop($table);   
  98.         foreach ($table as $key=>$tr) {   
  99.                 $td = explode('{td}'$tr);   
  100.                 array_pop($td);   
  101.             $td_array[] = $td;   
  102.         }   
  103.         return $td_array;   
  104. }  
  105. //返回字符串中的所有单词 $distinct=true 去除重复   
  106. function split_en_str($str,$distinct=true) {   
  107.         preg_match_all('/([a-zA-Z]+)/',$str,$match);   
  108.         if ($distinct == true) {   
  109.                 $match[1] = array_unique($match[1]);   
  110.         }   
  111.         sort($match[1]);   
  112.         return $match[1];   
  113. }  
  114.    
  115. 函数描述及例子  
  116.    
  117. PHP采集程序中常用的函数  
  118.  
  119. 查询关键字  
  120.    
  121. PHP采集程序中常用的函数  
  122. <!–?  
  123. //获得当前的脚本网址   
  124. function get_php_url(){   
  125.         if(!emptyempty($_SERVER["REQUEST_URI"])){   
  126.                 $scriptName = $_SERVER["REQUEST_URI"];   
  127.                 $nowurl = $scriptName;   
  128.         }else{   
  129.                 $scriptName = $_SERVER["PHP_SELF"];   
  130.                 if(emptyempty($_SERVER["QUERY_STRING"])) $nowurl = $scriptName;   
  131.                 else $nowurl = $scriptName."?".$_SERVER["QUERY_STRING"];   
  132.         }   
  133.         return $nowurl;   
  134. }   
  135. //把全角数字转为半角数字   
  136. function GetAlabNum($fnum){   
  137.         $nums = array("0","1","2","3","4","5","6","7","8","9");   
  138.         $fnums = "0123456789";   
  139.         for($i=0;$i<=9;$i++) $fnum = str_replace($nums[$i],$fnums[$i],$fnum);   
  140.         $fnum = ereg_replace("[^0-9.]|^0{1,}","",$fnum);   
  141.         if($fnum==""$fnum=0;   
  142.         return $fnum;   
  143. }   
  144. //去除HTML标记   
  145. function Text2Html($txt){   
  146.         $txt = str_replace("  "," ",$txt);   
  147.         $txt = str_replace("<","<",$txt);   
  148.         $txt = str_replace("–>",">",$txt);   
  149.         $txt = preg_replace("/[]{1,}/isU","  
  150. ",$txt);   
  151.         return $txt;   
  152. }  
  153. //清除HTML标记   
  154. function ClearHtml($str){   
  155.         $str = str_replace('<','<',$str);   
  156.         $str = str_replace('>','>',$str);   
  157.         return $str;   
  158. }   
  159. //相对路径转化成绝对路径   
  160. function relative_to_absolute($content$feed_url) {   
  161.     preg_match('/(http|https|ftp):///'$feed_url$protocol);   
  162.     $server_url = preg_replace("/(http|https|ftp|news):///"""$feed_url);   
  163.     $server_url = preg_replace("//.*/"""$server_url);  
  164.     if ($server_url == '') {   
  165.         return $content;   
  166.     }  
  167.     if (isset($protocol[0])) {   
  168.         $new_content = preg_replace('/href="//''href="'.$protocol[0].$server_url.'/'$content);   
  169.         $new_content = preg_replace('/src="//''src="'.$protocol[0].$server_url.'/'$new_content);   
  170.     } else {   
  171.         $new_content = $content;   
  172.     }   
  173.     return $new_content;   
  174. }   
  175. //取得所有链接   
  176. function get_all_url($code){   
  177.         preg_match_all('/<as+href=["|']?([^>"' ]+)["|']?s*[^>]*>([^>]+)</a>/i',$code,$arr);   
  178.         return array('name'=>$arr[2],'url'=>$arr[1]);   
  179. }  
  180. //获取指定标记中的内容   
  181. function get_tag_data($str$start$end){   
  182.         if ( $start == '' || $end == '' ){   
  183.                return;   
  184.         }   
  185.         $str = explode($start$str);   
  186.         $str = explode($end$str[1]);   
  187.         return $str[0];   
  188. }   
  189. //HTML表格的每行转为CSV格式数组   
  190. function get_tr_array($table) {   
  191.         $table = preg_replace("'<td[^>]*?>'si",'"',$table);   
  192.         $table = str_replace("",'",',$table);   
  193.         $table = str_replace("","{tr}",$table);   
  194.         //去掉 HTML 标记   
  195.         $table = preg_replace("'<[/!]*?[^<>]*?>'si","",$table);   
  196.         //去掉空白字符   
  197.         $table = preg_replace("'([])[s]+'","",$table);   
  198.         $table = str_replace(" ","",$table);   
  199.         $table = str_replace(" ","",$table);  
  200.         $table = explode(",{tr}",$table);   
  201.         array_pop($table);   
  202.         return $table;   
  203. }  
  204. //将HTML表格的每行每列转为数组,采集表格数据   
  205. function get_td_array($table) {   
  206.         $table = preg_replace("'<table[^>]*?>'si","",$table);   
  207.         $table = preg_replace("'<tr[^>]*?>'si","",$table);   
  208.         $table = preg_replace("'<td[^>]*?>'si","",$table);   
  209.         $table = str_replace("","{tr}",$table);   
  210.         $table = str_replace("","{td}",$table);   
  211.         //去掉 HTML 标记   
  212.         $table = preg_replace("'<[/!]*?[^<>]*?>'si","",$table);   
  213.         //去掉空白字符   
  214.         $table = preg_replace("'([])[s]+'","",$table);   
  215.         $table = str_replace(" ","",$table);   
  216.         $table = str_replace(" ","",$table);   
  217.           
  218.         $table = explode('{tr}'$table);   
  219.         array_pop($table);   
  220.         foreach ($table as $key=>$tr) {   
  221.                 $td = explode('{td}'$tr);   
  222.                 array_pop($td);   
  223.             $td_array[] = $td;   
  224.         }   
  225.         return $td_array;   
  226. }  
  227. //返回字符串中的所有单词 $distinct=true 去除重复   
  228. function split_en_str($str,$distinct=true) {   
  229.         preg_match_all('/([a-zA-Z]+)/',$str,$match);   
  230.         if ($distinct == true) {   
  231.                 $match[1] = array_unique($match[1]);   
  232.         }   
  233.         sort($match[1]);   
  234.         return $match[1];   
  235. }  
  236.    
  237. </td[^></tr[^></table[^></td[^></as+href=["|']?([^></td[^></tr[^></table[^></td[^></as+href=["|']?([^> 

 

波比源码 – 精品源码模版分享 | www.bobi11.com
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
7. 本站源码并不保证全部能正常使用,仅供有技术基础的人学习研究,请谨慎下载
8. 如遇到加密压缩包,请使用WINRAR解压,如遇到无法解压的请联系管理员!

波比源码 » PHP采集程序中常用的函数

1 评论

  1. Thank you for great content. Hello Administ. Metropol Halı Karaca Halı Öztekin ve Selçuklu Halı Cami Halısı ve Cami Halıları Türkiye’nin En Büyük Cami Halısı Fabrikasıyız…

发表评论

Hi, 如果你对这款模板有疑问,可以跟我联系哦!

联系站长
赞助VIP 享更多特权,建议使用 QQ 登录
喜欢我嘛?喜欢就按“ctrl+D”收藏我吧!♡