最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

PHP 采集程序 常用函數(shù)

 更新時(shí)間:2008年12月18日 14:21:29   作者:  
php中喜歡他的采集功能的朋友,就不的不參考下面的函數(shù)了,他們就是php采集程序中,常用的一些函數(shù)收集
當(dāng)前的腳本網(wǎng)址
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;
}
//把全角數(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("<","&lt;",$txt);
$txt = str_replace(">","&gt;",$txt);
$txt = preg_replace("/[\r\n]{1,}/isU","<br/>\r\n",$txt);
return $txt;
}
//清除HTML標(biāo)記
function ClearHtml($str){
$str = str_replace('<','&lt;',$str);
$str = str_replace('>','&gt;',$str);
return $str;
}
//相對(duì)路徑轉(zhuǎn)化成絕對(duì)路徑
function relative_to_absolute($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="\//', 'href="'.$protocol[0].$server_url.'/', $content);
$new_content = preg_replace('/src="\//', 'src="'.$protocol[0].$server_url.'/', $new_content);
} else {
$new_content = $content;
}
return $new_content;
}
//取得所有鏈接
function get_all_url($code){
preg_match_all('/<a\s+href=["|\']?([^>"\' ]+)["|\']?\s*[^>]*>([^>]+)<\/a>/i',$code,$arr);
return array('name'=>$arr[2],'url'=>$arr[1]);
}
//獲取指定標(biāo)記中的內(nèi)容
function get_tag_data($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 get_tr_array($table) {
$table = preg_replace("'<td[^>]*?>'si",'"',$table);
$table = str_replace("</td>",'",',$table);
$table = str_replace("</tr>","{tr}",$table);
//去掉 HTML 標(biāo)記
$table = preg_replace("'<[\/\!]*?[^<>]*?>'si","",$table);
//去掉空白字符
$table = preg_replace("'([\r\n])[\s]+'","",$table);
$table = str_replace(" ","",$table);
$table = str_replace(" ","",$table);
$table = explode(",{tr}",$table);
array_pop($table);
return $table;
}
//將HTML表格的每行每列轉(zhuǎn)為數(shù)組,采集表格數(shù)據(jù)
function get_td_array($table) {
$table = preg_replace("'<table[^>]*?>'si","",$table);
$table = preg_replace("'<tr[^>]*?>'si","",$table);
$table = preg_replace("'<td[^>]*?>'si","",$table);
$table = str_replace("</tr>","{tr}",$table);
$table = str_replace("</td>","{td}",$table);
//去掉 HTML 標(biāo)記
$table = preg_replace("'<[\/\!]*?[^<>]*?>'si","",$table);
//去掉空白字符
$table = preg_replace("'([\r\n])[\s]+'","",$table);
$table = str_replace(" ","",$table);
$table = str_replace(" ","",$table);
$table = explode('{tr}', $table);
array_pop($table);
foreach ($table as $key=>$tr) {
$td = explode('{td}', $tr);
array_pop($td);
$td_array[] = $td;
}
return $td_array;
}
//返回字符串中的所有單詞 $distinct=true 去除重復(fù)
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];
}

相關(guān)文章

  • php 錯(cuò)誤處理經(jīng)驗(yàn)分享

    php 錯(cuò)誤處理經(jīng)驗(yàn)分享

    在創(chuàng)建腳本和 web 應(yīng)用程序時(shí),錯(cuò)誤處理是一個(gè)重要的部分。如果您的代碼缺少錯(cuò)誤檢測(cè)編碼,那么程序看上去很不專業(yè),也為安全風(fēng)險(xiǎn)敞開了大門
    2011-10-10
  • php實(shí)現(xiàn)的XML操作(讀取)封裝類完整實(shí)例

    php實(shí)現(xiàn)的XML操作(讀取)封裝類完整實(shí)例

    這篇文章主要介紹了php實(shí)現(xiàn)的XML操作(讀取)封裝類,給出了xml格式文件示例,并結(jié)合完整實(shí)例形式分析了php遍歷讀取xml格式數(shù)據(jù)節(jié)點(diǎn)的相關(guān)操作技巧,需要的朋友可以參考下
    2017-02-02
  • PHP添加PNG圖片背景透明水印操作類定義與用法示例

    PHP添加PNG圖片背景透明水印操作類定義與用法示例

    這篇文章主要介紹了PHP添加PNG圖片背景透明水印操作類定義與用法,涉及php操作圖片的顯示、保存、壓縮、水印添加等相關(guān)操作技巧,需要的朋友可以參考下
    2019-03-03
  • PHP封裝的遠(yuǎn)程抓取網(wǎng)站圖片并保存功能類

    PHP封裝的遠(yuǎn)程抓取網(wǎng)站圖片并保存功能類

    這篇文章主要介紹了PHP封裝的遠(yuǎn)程抓取網(wǎng)站圖片并保存功能類,結(jié)合實(shí)例形式分析了php抓取遠(yuǎn)程圖片封裝類的定義與簡(jiǎn)單使用方法,涉及php正則匹配與文件讀寫相關(guān)操作技巧,需要的朋友可以參考下
    2018-06-06
  • mac下Apache + MySql + PHP搭建網(wǎng)站開發(fā)環(huán)境

    mac下Apache + MySql + PHP搭建網(wǎng)站開發(fā)環(huán)境

    最近接了個(gè)小活,做一個(gè)使用PHP語(yǔ)言和MySql數(shù)據(jù)庫(kù)的動(dòng)態(tài)網(wǎng)站。之前做過類型的網(wǎng)站,是在windows系統(tǒng)下做的,開發(fā)環(huán)境使用的是 AppServ 的PHP開發(fā)套件。現(xiàn)在有了我的大MAC,所以找了MAC系統(tǒng)下PHP環(huán)境的開發(fā)套件。
    2014-06-06
  • thinkphp5.0自定義驗(yàn)證規(guī)則使用方法

    thinkphp5.0自定義驗(yàn)證規(guī)則使用方法

    本文主要講了thinkphp5.0版本中自定義驗(yàn)證規(guī)則的使用方法和一些注意事項(xiàng)。
    2017-11-11
  • PHP 配置open_basedir 讓各虛擬站點(diǎn)獨(dú)立運(yùn)行

    PHP 配置open_basedir 讓各虛擬站點(diǎn)獨(dú)立運(yùn)行

    好幾年前,我在抱怨Apache運(yùn)行PHP的安全性不行,只要一個(gè)站點(diǎn)被人拿下,服務(wù)器上的其他站點(diǎn)就會(huì)跟著遭殃。
    2009-11-11
  • 一個(gè)簡(jiǎn)單php擴(kuò)展介紹與開發(fā)教程

    一個(gè)簡(jiǎn)單php擴(kuò)展介紹與開發(fā)教程

    這個(gè)擴(kuò)展早就寫好了,只是一直沒有時(shí)間寫在blog上面,今天抽點(diǎn)時(shí)間,將它記錄下來,以后備用。
    2010-08-08
  • 解決PHP 7編譯安裝錯(cuò)誤:cannot stat ‘phar.phar’: No such file or directory

    解決PHP 7編譯安裝錯(cuò)誤:cannot stat ‘phar.phar’: No such file or direc

    這篇文章主要給大家介紹了關(guān)于解決在PHP 7編譯安裝遇到的錯(cuò)誤錯(cuò)誤:cannot stat ‘phar.phar’: No such file or directory問題的相關(guān)資料,文中給出詳細(xì)的解決方法,需要的朋友可以參考借鑒。
    2017-02-02
  • PHP中流的定義及作用詳解

    PHP中流的定義及作用詳解

    流的作用是在出發(fā)地和目的地之間傳輸數(shù)據(jù)。出發(fā)地和目的地可以是文件、命令行進(jìn)程、網(wǎng)絡(luò)連接、ZIP或TAR壓縮文件、臨時(shí)內(nèi)存、標(biāo)準(zhǔn)輸入或輸出,或是通過PHP流封裝協(xié)議實(shí)現(xiàn)的任何其它資源
    2022-11-11

最新評(píng)論

九台市| 秭归县| 乾安县| 伊金霍洛旗| 邢台县| 沙洋县| 元阳县| 安仁县| 南部县| 揭阳市| 潮安县| 丰顺县| 宜昌市| 乌兰浩特市| 西乌| 彭州市| 贵溪市| 綦江县| 花垣县| 梅河口市| 肥城市| 克山县| 资源县| 靖宇县| 如东县| 广昌县| 建水县| 皮山县| 上饶县| 饶平县| 凤翔县| 海淀区| 连城县| 渝北区| 博白县| 鸡东县| 许昌市| 浦北县| 河源市| 万年县| 白朗县|