DDR爱好者之家 Design By 杰米
<?php
/*********************************
*
*  作者: 徐祖宁 (唠叨)
*  邮箱: czjsz_ah@stats.gov.cn
*  开发: 2002.07
*
*
*  函数: tags
*  功能: 从文件中提取HTML标签
*
*  入口:
*  $filename 文件名
*  $tag      标签名
*  返回:
*  数组,每项为:
*   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;
}

?>

DDR爱好者之家 Design By 杰米
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
DDR爱好者之家 Design By 杰米