php 採集常用函式 PHP 採集程式中常用的函式

2021-10-22 21:52:55 字數 3149 閱讀 7892

//獲得當前的指令碼**

function get_php_url()

if(!empty($_server[」request_uri」]))

$scriptname = $_server[」request_uri」];

$nowurl = $scriptname;

else

$scriptname = $_server[」php_self」];

if(empty($_server[」query_string」]))

$nowurl = $scriptname;

else

$nowurl = $scriptname.」?」.$_server[」query_string」];

return $nowurl;

//把全形數字轉為半形數字

function getalabnum($fnum)

$nums = array(」0」,」1」,」2」,」3」,」4」,」5」,」6」,」7」,」8」,」9」);

$fnums = 「0123456789″;

for($i=0;$i<=9;$i++) $fnum = str_replace($nums[$i],$fnums[$i],$fnum);

$fnum = ereg_replace(」[^0-9\.]|^0」,」」,$fnum);

if($fnum==」」) $fnum=0;

return $fnum;

//去除html標記

function text2html($txt)

$txt = str_replace(」 「,」 」,$txt);

$txt = str_replace(」

$txt = str_replace(」>」,」>」,$txt);

$txt = preg_replace(」/[\r\n]/isu」,」

\r\n」,$txt);

return $txt;

//清除html標記

function clearhtml($str)

$str = str_replace('

$str = str_replace('>','>',$str);

return $str;

//相對路徑轉化成絕對路徑

//取得所有鏈結

function get_all_url($code)」,$table);

//去掉 html 標記

$table = preg_replace(」『]*?>'si」,」」,$table);

//去掉空白字元

$table = preg_replace(」『([\r\n])[\s]+'」,」」,$table);

$table = str_replace(」 「,」」,$table);

$table = str_replace(」 「,」」,$table);

$table = explode(」,」,$table);

array_pop($table);

return $table;

//將html**的每行每列轉為陣列,採集**資料

function get_td_array($table)

$table = preg_replace(」『

$table = preg_replace(」『

]*?>'si」,」」,$table);

$table = preg_replace(」『

]*?>'si」,」」,$table);

$table = str_replace(」

」,」」,$table);

$table = str_replace(」」,」」,$table);

//去掉 html 標記

$table = preg_replace(」『]*?>'si」,」」,$table);

//去掉空白字元

$table = preg_replace(」『([\r\n])[\s]+'」,」」,$table);

$table = str_replace(」 「,」」,$table);

$table = str_replace(」 「,」」,$table);

$table = explode('', $table);

array_pop($table);

foreach ($table as $key=>$tr)

$td = explode('', $tr);

array_pop($td);

$td_array = $td;

return $td_array;

//返回字串中的所有單詞 $distinct=true 去除重複

function split_en_str($str,$distinct=true)

preg_match_all('/([a-za-z]+)/',$str,$match);

if ($distinct == true)

$match[1] = array_unique($match[1]);

sort($match[1]);

return $match[1];

php 採集常用函式 PHP常用採集函式

獲取所有鏈結內容和位址function getallurl code 獲取所有的位址 function getimgsrc code else fnum if fnum fnum 0 return fnum 去除html標記 function text2html txt isu r n txt re...

PHP採集程式常用的採集函式

這幾天關注了一下php的採集程式,才發現用php採集內容是這麼方便,把經常用到的採集函式在這裡總結一下,方便以後使用 function getallurl code else fnum if fnum fnum 0 return fnum 去除html標記 function text2html tx...

PHP 採集程式 常用函式

php中喜歡他的採集功能的朋友,就不的不參考下面的函式了,他們就是php採集程式中,常用的一些函式收集 當前的指令碼 function get php url else return nowurl 把全形數字轉為半形數字 function getalabnum fnum fnum if fnum f...