php专区

 首页 > php专区 > PHP应用 > php函数大全 > PHP采集程序中常用的函数 - php函数

PHP采集程序中常用的函数 - php函数

分享到:
【字体:
导读:
          函数描述及例子 PHP采集程序中常用的函数 查询关键字 PHP采集程序中常用的函数 获得当前的脚本网址 functionget_php_url(){ if(!empt...

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("/[rn]{1,}/isU","  
  28. rn",$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('/"' ]+)["|']?s*[^>]*>([^>]+)/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("']*?>'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("'([rn])[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("']*?>'si","",$table);   
  85.         $table = preg_replace("']*?>'si","",$table);   
  86.         $table = preg_replace("']*?>'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("'([rn])[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. ",">",$txt);   
  123.         $txt = preg_replace("/[rn]{1,}/isU","  
  124. rn",$txt);   
  125.         return $txt;   
  126. }  
  127. //清除HTML标记   
  128. function ClearHtml($str){   
  129.         $str = str_replace('<','<',$str);   
  130.         $str = str_replace('>','>',$str);   
  131.         return $str;   
  132. }   
  133. //相对路径转化成绝对路径   
  134. function relative_to_absolute($content$feed_url) {   
  135.     preg_match('/(http|https|ftp):///'$feed_url$protocol);   
  136.     $server_url = preg_replace("/(http|https|ftp|news):///"""$feed_url);   
  137.     $server_url = preg_replace("//.*/"""$server_url);  
  138.     if ($server_url == '') {   
  139.         return $content;   
  140.     }  
  141.     if (isset($protocol[0])) {   
  142.         $new_content = preg_replace('/href="//''href="'.$protocol[0].$server_url.'/'$content);   
  143.         $new_content = preg_replace('/src="//''src="'.$protocol[0].$server_url.'/'$new_content);   
  144.     } else {   
  145.         $new_content = $content;   
  146.     }   
  147.     return $new_content;   
  148. }   
  149. //取得所有链接   
  150. function get_all_url($code){   
  151.         preg_match_all('/"' ]+)["|']?s*[^>]*>([^>]+)/i',$code,$arr);   
  152.         return array('name'=>$arr[2],'url'=>$arr[1]);   
  153. }  
  154. //获取指定标记中的内容   
  155. function get_tag_data($str$start$end){   
  156.         if ( $start == '' || $end == '' ){   
  157.                return;   
  158.         }   
  159.         $str = explode($start$str);   
  160.         $str = explode($end$str[1]);   
  161.         return $str[0];   
  162. }   
  163. //HTML表格的每行转为CSV格式数组   
  164. function get_tr_array($table) {   
  165.         $table = preg_replace("']*?>'si",'"',$table);   
  166.         $table = str_replace("",'",',$table);   
  167.         $table = str_replace("","{tr}",$table);   
  168.         //去掉 HTML 标记   
  169.         $table = preg_replace("'<[/!]*?[^<>]*?>'si","",$table);   
  170.         //去掉空白字符   
  171.         $table = preg_replace("'([rn])[s]+'","",$table);   
  172.         $table = str_replace(" ","",$table);   
  173.         $table = str_replace(" ","",$table);  
  174.         $table = explode(",{tr}",$table);   
  175.         array_pop($table);   
  176.         return $table;   
  177. }  
  178. //将HTML表格的每行每列转为数组,采集表格数据   
  179. function get_td_array($table) {   
  180.         $table = preg_replace("']*?>'si","",$table);   
  181.         $table = preg_replace("']*?>'si","",$table);   
  182.         $table = preg_replace("']*?>'si","",$table);   
  183.         $table = str_replace("","{tr}",$table);   
  184.         $table = str_replace("","{td}",$table);   
  185.         //去掉 HTML 标记   
  186.         $table = preg_replace("'<[/!]*?[^<>]*?>'si","",$table);   
  187.         //去掉空白字符   
  188.         $table = preg_replace("'([rn])[s]+'","",$table);   
  189.         $table = str_replace(" ","",$table);   
  190.         $table = str_replace(" ","",$table);   
  191.           
  192.         $table = explode('{tr}'$table);   
  193.         array_pop($table);   
  194.         foreach ($table as $key=>$tr) {   
  195.                 $td = explode('{td}'$tr);   
  196.                 array_pop($td);   
  197.             $td_array[] = $td;   
  198.         }   
  199.         return $td_array;   
  200. }  
  201. //返回字符串中的所有单词 $distinct=true 去除重复   
  202. function split_en_str($str,$distinct=true) {   
  203.         preg_match_all('/([a-zA-Z]+)/',$str,$match);   
  204.         if ($distinct == true) {   
  205.                 $match[1] = array_unique($match[1]);   
  206.         }   
  207.         sort($match[1]);   
  208.         return $match[1];   
  209. }  
  210.    
  211. "|']?([^>|']?([^> 

 

分享到:
PHP多重判断删除文件函数 - php函数
PHP多重判断删除文件函数 函数描述及例子 PHP多重判断删除文件函数 查询关键字 PHP多重判断删除文件函数 &#039;.$file.&#039;   &#039;;            }            else            {                return &#039;Delete Succ...
PHP不缓存数据头 - php函数
PHP不缓存数据头 PHP不缓存数据头 function nocache_headers() {        // why are these @-silenced when other header calls aren&#039;t?        @header( &#039;Expires: Wed, 11 Jan 1984 05:00:00 GMT&#039; );        @header(...
  •         php迷,一个php技术的分享社区,专属您自己的技术摘抄本、收藏夹。
  • 在这里……