Extract HTML tags .? Php *********************************** author: xu Zening (nagging) * mailbox: czjsz_ah@stats.gov.cn * development: 2002.07 *** function: tags * function: extract HTML tags from files ** entry /*********************************
*
* Author: Xu zouning)
* Email: czjsz_ah@stats.gov.cn
* Development: 2002.07
*
*
* Function: tags
* Function: extract HTML tags from files
*
* Entry:
* $ Filename file name
* $ Tag name
* Return value:
* Array, each of which is:
* TagName String
* Text String
* Attrs Array
*
* Example:
* Print_r (tags ("test1.htm", ""));
* 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 ([^>] *) (. *) $ 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 $ 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;
}
?>
Http://www.bkjia.com/PHPjc/315020.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/315020.htmlTechArticle? Php/********************************** author: xu Zening (nagging) * mailbox: czjsz_ah@stats.gov.cn * development: 2002.07 *** function: tags * function: extract HTML tag from FILE ** entry...