|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- <?php
-
-
-
- class DedeAtt
- {
- var $Count = -1;
- var $Items = "";
-
-
-
- function GetAtt($str)
- {
- if($str=="")
- {
- return "";
- }
- if(isset($this->Items[$str]))
- {
- return $this->Items[$str];
- }
- else
- {
- return "";
- }
- }
-
-
- function GetAttribute($str)
- {
- return $this->GetAtt($str);
- }
-
-
-
- function IsAttribute($str)
- {
- return isset($this->Items[$str]) ? TRUE : FALSE;
- }
-
-
-
- function GetTagName()
- {
- return $this->GetAtt("tagname");
- }
-
-
-
- function GetCount()
- {
- return $this->Count+1;
- }
- }
-
-
- class DedeAttParse
- {
- var $SourceString = "";
- var $SourceMaxSize = 1024;
- var $CAtt = "";
- var $CharToLow = TRUE;
-
-
-
- function SetSource($str="")
- {
- $this->CAtt = new DedeAtt();
- $strLen = 0;
- $this->SourceString = trim(preg_replace("/[ \t\r\n]{1,}/"," ",$str));
- $strLen = strlen($this->SourceString);
- if($strLen>0&&$strLen<=$this->SourceMaxSize)
- {
- $this->ParseAtt();
- }
- }
-
-
-
- function ParseAtt()
- {
- $d = "";
- $tmpatt="";
- $tmpvalue="";
- $startdd=-1;
- $ddtag="";
- $notAttribute=TRUE;
- $strLen = strlen($this->SourceString);
-
-
-
-
- for($i=0;$i<$strLen;$i++)
- {
- $d = substr($this->SourceString,$i,1);
- if($d==' ')
- {
- $this->CAtt->Count++;
- if($this->CharToLow)
- {
- $this->CAtt->Items["tagname"]=strtolower(trim($tmpvalue));
- }
- else
- {
- $this->CAtt->Items["tagname"]=trim($tmpvalue);
- }
- $tmpvalue = "";
- $notAttribute = FALSE;
- break;
- }
- else
- {
- $tmpvalue .= $d;
- }
- }
-
-
- if($notAttribute)
- {
- $this->CAtt->Count++;
- $this->CAtt->Items["tagname"]= ($this->CharToLow ? strtolower(trim($tmpvalue)) : trim($tmpvalue));
- }
-
-
- if(!$notAttribute)
- {
- for($i;$i<$strLen;$i++)
- {
- $d = substr($this->SourceString,$i,1);
- if($startdd==-1)
- {
- if($d!="=")
- {
- $tmpatt .= $d;
- }
- else
- {
- if($this->CharToLow)
- {
- $tmpatt = strtolower(trim($tmpatt));
- }
- else
- {
- $tmpatt = trim($tmpatt);
- }
- $startdd=0;
- }
- }
- else if($startdd==0)
- {
- switch($d)
- {
- case ' ':
-
- break;
- case '\'':
- $ddtag='\'';
- $startdd=1;
- break;
- case '"':
- $ddtag='"';
- $startdd=1;
- break;
- default:
- $tmpvalue.=$d;
- $ddtag=' ';
- $startdd=1;
- break;
- }
- }
- else if($startdd==1)
- {
- if($d==$ddtag)
- {
- $this->CAtt->Count++;
- $this->CAtt->Items[$tmpatt] = trim($tmpvalue);
- $tmpatt = "";
- $tmpvalue = "";
- $startdd=-1;
- }
- else
- {
- $tmpvalue.=$d;
- }
- }
- }
- if($tmpatt!="")
- {
- $this->CAtt->Count++;
- $this->CAtt->Items[$tmpatt]=trim($tmpvalue);
- }
-
- }
-
- }
- }
|