麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 語言 > PHP > 正文

PHP采集程序中常用的函數

2024-09-04 11:47:42
字體:
來源:轉載
供稿:網友
函數描述及例子 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("/[/r/n]{1,}/isU","  
  28. /r/n",$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('/<a/s+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("'([/r/n])[/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("'([/r/n])[/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("/[/r/n]{1,}/isU","  
  150. /r/n",$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('/<a/s+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("'([/r/n])[/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("'([/r/n])[/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[^></a/s+href=["|/']?([^></td[^></tr[^></table[^></td[^></a/s+href=["|/']?([^> 

 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 亚洲欧美日韩中文在线 | 国产精品久久av | 国产一级毛片高清视频完整版 | 久久久久久久久久久综合 | 亚洲一区二区 | 午夜免费一区 | 日产精品久久久一区二区开放时间 | 精品999www | 久章草在线视频 | 欧美一级黄色免费 | 毛片视频播放 | 欧美成年性h版影视中文字幕 | 久久精品23| 精品1| 日韩精品久久久久久久九岛 | 蜜桃一本色道久久综合亚洲精品冫 | 成年人视频免费 | 在线播放免费视频 | 毛片免费观看日本中文 | 午夜小影院 | 欧美成人小视频 | 一级大黄毛片 | 在线中文字幕网站 | 欧美三级日本三级少妇99 | 黄色毛片一级视频 | 亚洲一区二区在线视频 | 欧美一级爱爱 | 午夜精品老牛av一区二区三区 | 国产精品一区二区三区在线播放 | 国产精品久久久久久久久久久久久久久久 | 国产亚洲精品成人 | 成人啪啪18免费网站 | 国产一区二区精品在线观看 | 媚药按摩痉挛w中文字幕 | 黄色免费高清网站 | av在线试看 | 在线播放黄色网址 | 日韩一级成人 | av在线久草 | 九九精品视频免费 | 日韩欧美电影在线观看 |