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

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

 更新時(shí)間:2009年12月09日 19:05:21   作者:  
現(xiàn)在不少的php采集程序,用了下面的函數(shù),需要的朋友可以參考下。

復(fù)制代碼 代碼如下:

//獲得當(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中將地址生成迅雷快車旋風(fēng)鏈接的代碼[測(cè)試通過(guò)]

    php中將地址生成迅雷快車旋風(fēng)鏈接的代碼[測(cè)試通過(guò)]

    php中將地址生成迅雷快車旋風(fēng)鏈接的代碼,非常不錯(cuò),將下面的代碼保存為cs.php運(yùn)行即可。
    2011-04-04
  • php簡(jiǎn)單計(jì)算年齡的方法(周歲與虛歲)

    php簡(jiǎn)單計(jì)算年齡的方法(周歲與虛歲)

    這篇文章主要介紹了php簡(jiǎn)單計(jì)算年齡的方法,通過(guò)自定義函數(shù)實(shí)現(xiàn)針對(duì)周歲與虛歲的簡(jiǎn)單計(jì)算功能,涉及php日期與時(shí)間相關(guān)操作技巧,需要的朋友可以參考下
    2016-12-12
  • Admin generator, filters and I18n

    Admin generator, filters and I18n

    You need to modify your EntityFormFilter (where Entity is your object class - Article, Book, etc.).
    2011-10-10
  • PHP獲取文件屬性的最簡(jiǎn)單方法

    PHP獲取文件屬性的最簡(jiǎn)單方法

    在本篇文章里小編給大家分享了一篇關(guān)于PHP獲取文件屬性的最簡(jiǎn)單方法,有需要的朋友們學(xué)習(xí)下吧。
    2021-08-08
  • 介紹一些PHP判斷變量的函數(shù)

    介紹一些PHP判斷變量的函數(shù)

    與其他語(yǔ)言不同,PHP不是一種嚴(yán)格的類型語(yǔ)言?;旧?,這意味著開發(fā)者在使用一個(gè)變量前,不必明確地設(shè)定這個(gè)變量的類型(數(shù)字、字符串、布爾值)。相反,PHP解釋程序根據(jù)存儲(chǔ)在變量中的信息自動(dòng)探測(cè)變量的類型
    2012-04-04
  • PHP字符串word末字符實(shí)現(xiàn)大小寫互換的方法

    PHP字符串word末字符實(shí)現(xiàn)大小寫互換的方法

    這篇文章主要介紹了PHP字符串word末字符實(shí)現(xiàn)大小寫互換的方法,是涉及PHP字符串轉(zhuǎn)換非常實(shí)用的技巧,需要的朋友可以參考下
    2014-11-11
  • php操作ElasticSearch搜索引擎流程詳解

    php操作ElasticSearch搜索引擎流程詳解

    ElasticSearch是一個(gè)基于Lucene的搜索引擎,是用Java語(yǔ)言開發(fā)的,能夠達(dá)到實(shí)時(shí)搜索,穩(wěn)定,可靠,快速,安裝使用方便,作為Apache許可條款下的開放源碼發(fā)布,是一種流行的企業(yè)級(jí)搜索引擎,是最受歡迎的企業(yè)搜索引擎
    2021-11-11
  • php 批量生成html,txt文件的實(shí)現(xiàn)代碼

    php 批量生成html,txt文件的實(shí)現(xiàn)代碼

    本篇文章是對(duì)使用php批量生成html,txt文件的實(shí)現(xiàn)代碼進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-06-06
  • PHP網(wǎng)頁(yè)緩存技術(shù)優(yōu)點(diǎn)及代碼實(shí)例

    PHP網(wǎng)頁(yè)緩存技術(shù)優(yōu)點(diǎn)及代碼實(shí)例

    這篇文章主要介紹了PHP網(wǎng)頁(yè)緩存技術(shù)優(yōu)點(diǎn)及代碼實(shí)例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-07-07
  • Gregarius中文日期格式問題解決辦法

    Gregarius中文日期格式問題解決辦法

    Gregarius支持中文的程度很不錯(cuò),唯一的缺陷就是在日期格式上會(huì)出現(xiàn)亂碼。其實(shí)只要修改根目錄下util.php文件的rss_locale_date方法就可以解決這個(gè)問題,希望可以幫助使用Gregarius的朋友,修改后的方法代碼如下:
    2008-04-04

最新評(píng)論

卢湾区| 绥江县| 广昌县| 营口市| 丹巴县| 兰溪市| 台东县| 綦江县| 平武县| 贵溪市| 郸城县| 公安县| 永定县| 沐川县| 江津市| 岐山县| 河间市| 太原市| 奈曼旗| 郧西县| 余庆县| 西安市| 马边| 株洲县| 丰都县| 勃利县| 天长市| 韶关市| 托克托县| 定结县| 涿鹿县| 泊头市| 中山市| 澎湖县| 陇南市| 广德县| 衡南县| 阳山县| 全椒县| 育儿| 苗栗市|