提取HTML標(biāo)簽
更新時(shí)間:2006年10月09日 00:00:00 作者:
<?php
/*********************************
*
* 作者: 徐祖寧 (嘮叨)
* 郵箱: czjsz_ah@stats.gov.cn
* 開發(fā): 2002.07
*
*
* 函數(shù): tags
* 功能: 從文件中提取HTML標(biāo)簽
*
* 入口:
* $filename 文件名
* $tag 標(biāo)簽名
* 返回:
* 數(shù)組,每項(xiàng)為:
* tagName String
* Text String
* Attrs Array
*
* 示例:
* print_r(tags("test1.htm","a"));
* print_r("http://localhost/index.htm","img");
*
*/
function tags($filename,$tag) {
$buffer = join("",file($filename));
$buffer = eregi_replace("\r\n","",$buffer);
$tagkey = sql_regcase($tag);
$buffer = eregi_replace("<$tagkey ","\n<$tag ",$buffer);
$ar = split("\n",$buffer);
foreach($ar as $v) {
if(! eregi("<$tagkey ",$v)) continue;
eregi("<$tagkey ([^>]*)((.*)</$tagkey)?",$v,$regs);
$p[tagName] = strtoupper($tag);
if($regs[3])
$p[Text] = $regs[3];
$s = trim(eregi_replace("[ \t]+"," ",$regs[1]))." ";
$s = eregi_replace(" *= *","=",$s);
$a = split(" ",$s);
for($i=0;$i<count($a);$i++) {
$ch = array();
if(eregi("=[\"']",$a[$i])) {
$j = $i+1;
while(!eregi("[\"']$",$a[$i])) {
$a[$i] .= " ".$a[$j];
unset($a[$j]);
}
}
}
foreach($a as $k) {
$name = strtoupper(strtok($k,"="));
$value = strtok("\0");
if(eregi("^[\"']",$value))
$value = substr($value,1,-1);
if($name)
$p[Attrs][$name] = $value;
}
$pp[] = $p;
}
return $pp;
}
?>
/*********************************
*
* 作者: 徐祖寧 (嘮叨)
* 郵箱: czjsz_ah@stats.gov.cn
* 開發(fā): 2002.07
*
*
* 函數(shù): tags
* 功能: 從文件中提取HTML標(biāo)簽
*
* 入口:
* $filename 文件名
* $tag 標(biāo)簽名
* 返回:
* 數(shù)組,每項(xiàng)為:
* tagName String
* Text String
* Attrs Array
*
* 示例:
* print_r(tags("test1.htm","a"));
* print_r("http://localhost/index.htm","img");
*
*/
function tags($filename,$tag) {
$buffer = join("",file($filename));
$buffer = eregi_replace("\r\n","",$buffer);
$tagkey = sql_regcase($tag);
$buffer = eregi_replace("<$tagkey ","\n<$tag ",$buffer);
$ar = split("\n",$buffer);
foreach($ar as $v) {
if(! eregi("<$tagkey ",$v)) continue;
eregi("<$tagkey ([^>]*)((.*)</$tagkey)?",$v,$regs);
$p[tagName] = strtoupper($tag);
if($regs[3])
$p[Text] = $regs[3];
$s = trim(eregi_replace("[ \t]+"," ",$regs[1]))." ";
$s = eregi_replace(" *= *","=",$s);
$a = split(" ",$s);
for($i=0;$i<count($a);$i++) {
$ch = array();
if(eregi("=[\"']",$a[$i])) {
$j = $i+1;
while(!eregi("[\"']$",$a[$i])) {
$a[$i] .= " ".$a[$j];
unset($a[$j]);
}
}
}
foreach($a as $k) {
$name = strtoupper(strtok($k,"="));
$value = strtok("\0");
if(eregi("^[\"']",$value))
$value = substr($value,1,-1);
if($name)
$p[Attrs][$name] = $value;
}
$pp[] = $p;
}
return $pp;
}
?>
相關(guān)文章
使用php通過Socket進(jìn)行發(fā)信源碼,支持發(fā)信認(rèn)證
使用php通過Socket進(jìn)行發(fā)信源碼,支持發(fā)信認(rèn)證...2006-10-10PHP html_entity_decode()函數(shù)講解
今天小編就為大家分享一篇關(guān)于PHP html_entity_decode()函數(shù)講解,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧2019-02-02PHP調(diào)用三種數(shù)據(jù)庫的方法(3)
PHP調(diào)用三種數(shù)據(jù)庫的方法(3)...2006-10-10PHP registerXPathNamespace()函數(shù)講解
今天小編就為大家分享一篇關(guān)于PHP registerXPathNamespace()函數(shù)講解,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧2019-02-02php讀取本地文件常用函數(shù)(fopen與file_get_contents)
下面我們以.txt文件為實(shí)例來介紹php讀取本地文件的函數(shù),讀取文件我們可以利用fopen或file_get_contents來讀取,file_get_contents更簡單而fopen需要fread配合才可以顯示讀出的內(nèi)容2013-09-09php radio 單選框獲取與保持值的實(shí)現(xiàn)代碼
php中讀取單選框radio值的與在php中保持單選按鈕的值的方法,其實(shí)都是一樣的原理。2010-05-05