【php采集安裝教程 Python數(shù)據(jù)采集流程】本篇文章給大家?guī)淼膬?nèi)容是關(guān)于php中常用的采集函數(shù)的總結(jié)(附代碼),有一定的參考價(jià)值,有需要的朋友可以參考一下,希望對你有所幫助 。

這幾天關(guān)注了一下PHP的采集程序,才發(fā)現(xiàn)用PHP采集內(nèi)容是這么方便,把經(jīng)常用到的采集函數(shù)在這里總結(jié)一下,方便以后使用!
獲取所有鏈接內(nèi)容和地址
function getAllURL($code){
preg_match_all(‘/”‘ ]+)[“|’]?s*[^>]*>([^>]+)/i’,$code,$arr);
return array(‘name’=>$arr[2],’url’=>$arr[1]);
}
獲取所有的圖片地址
function getImgSrc($code){
$reg = “/]*src=https://www.jinnalai.com/fenxiang/”(http://(.+)/(.+).(jpg|gif|bmp|bnp|png))”/isU”;
preg_match_all($reg, $code, $img_array, PREG_PATTERN_ORDER);
return $img_array[1];
}
當(dāng)前的腳本網(wǎng)址
function getSelfURL(){
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;
}
把全角數(shù)字轉(zhuǎn)為半角數(shù)字
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{1,}”,””,$fnum);
if($fnum==””) $fnum=0;
return $fnum;
}

去除HTML標(biāo)記
function text2Html($txt){
$txt = str_replace(” “,” ”,$txt);
$txt = str_replace(“<“,”<“,$txt);
$txt = str_replace(“>”,”>”,$txt);
$txt = preg_replace(“/[rn]{1,}/isU”,”
rn”,$txt);
return $txt;
}
清除HTML標(biāo)記
function clearHtml($str){
$str = str_replace(‘<‘,'<‘,$str);
$str = str_replace(‘>’,’>’,$str);
return $str;
}
相對路徑轉(zhuǎn)化成絕對路徑
function relative2Absolute($content, $feed_url) {
preg_match(‘/(http|https|ftp):///’, $feed_url, $protocol);
$server_url = preg_replace(“/(http|https|ftp|news):///”, “”, $feed_url);
$server_url = preg_replace(“//.*/”, “”, $server_url);
if ($server_url == ”) {
return $content;
}
if (isset($protocol[0])) {
$new_content = preg_replace(‘/href=https://www.jinnalai.com/fenxiang/”//’, ‘href=”‘.$protocol[0].$server_url.’/’, $content);
$new_content = preg_replace(‘/src=https://www.jinnalai.com/fenxiang/”//’, ‘src=”‘.$protocol[0].$server_url.’/’, $new_content);
} else {
$new_content = $content;
}
return $new_content;
}
獲取指定標(biāo)記中的內(nèi)容
function getTagData($str, $start, $end){
if ( $start == ” || $end == ” ){
return;
}
$str = explode($start, $str);
$str = explode($end, $str[1]);
return $str[0];
}

HTML表格的每行轉(zhuǎn)為CSV格式數(shù)組
function getTrArray($table) {
$table = preg_replace(“‘]*?>’si”,’”‘,$table);
$table = str_replace(“”,’”,’,$table);
$table = str_replace(“”,”{tr}”,$table);
//去掉 HTML 標(biāo)記
$table = preg_replace(“‘<[/!]*?[^<>]*?>’si”,””,$table);
//去掉空白字符
$table = preg_replace(“‘([rn])[s]+’”,””,$table);
推薦閱讀
- 立升凈水超濾機(jī)說明書 立升凈水器安裝方法
- 懸掛指示牌的懸掛高度 安全標(biāo)識牌安裝標(biāo)準(zhǔn)
- 綜合訓(xùn)練機(jī)安裝方法 綜合訓(xùn)練器的組裝步驟
- nsi文件怎么安裝 NSIS制作安裝包步驟
- iOS版QQ安裝包暴漲至879M 竟內(nèi)置虛幻4引擎
- 愛普生lq630kii安裝驅(qū)動 愛普生630k與630kii的區(qū)別
- 貝親學(xué)飲杯怎么安裝 好用的學(xué)飲杯推薦
- 夢夢奈安裝方法 夢夢奈使用攻略
- 風(fēng)色幻想命運(yùn)傳說首測內(nèi)容介紹 風(fēng)色幻想首測玩法安裝包大小信息
- 核酸采集碼會過期嗎
