PHP Parse error: syntax error, unexpected ')' in D:\phpEnv\www\720\App\Lib\Class\mytag.class.php on line 155
<?php
class MyTag
{
public $IsReplace = FALSE;
public $TagName = "";
public $InnerText = "";
public $StartPos = 0;
public $EndPos = 0;
public $CAttribute = "";
public $TagValue = "";
public $TagID = 0;
public function GetName( )
{
return strtolower( $this->TagName );
}
public function GetValue( )
{
return $this->TagValue;
}
public function GetTagName( )
{
return strtolower( $this->TagName );
}
public function GetTagValue( )
{
return $this->TagValue;
}
public function IsAttribute( $str )
{
return $this->CAttribute->IsAttribute( $str );
}
public function GetAttribute( $str )
{
return $this->CAttribute->GetAtt( $str );
}
public function GetAtt( $str )
{
return $this->CAttribute->GetAtt( $str );
}
public function GetInnerText( )
{
return $this->InnerText;
}
}
class MyTagParse
{
public $NameSpace = "boluo";
public $TagStartWord = "{";
public $TagEndWord = "}";
public $TagMaxLen = 64;
public $CharToLow = TRUE;
public $IsCache = FALSE;
public $TempMkTime = 0;
public $CacheFile = "";
public $SourceString = "";
public $CTags = "";
public $Count = -1;
public $refObj = "";
public function __construct( )
{
$this->IsCache = FALSE;
$this->NameSpace = "boluo";
$this->TagStartWord = "{";
$this->TagEndWord = "}";
$this->TagMaxLen = 100000;
$this->CharToLow = TRUE;
$this->SourceString = "";
$this->CTags = array( );
$this->Count = -1;
$this->TempMkTime = 0;
$this->CacheFile = "";
}
public function SetNameSpace( $str, $s = "{", $e = "}" )
{
$this->NameSpace = strtolower( $str );
$this->TagStartWord = $s;
$this->TagEndWord = $e;
}
public function SetDefault( )
{
$this->SourceString = "";
$this->CTags = "";
$this->Count = -1;
}
public function SetRefObj( &$refObj )
{
$this->refObj = $refObj;
}
public function GetCount( )
{
return $this->Count + 1;
}
public function Clear( )
{
$this->SetDefault( );
}
public function LoadCache( $filename )
{
if ( !$this->IsCache )
{
return FALSE;
}
$cdir = dirname( $filename );
$cachedir = APP_ROOT."/Cache";
if ( !is_dir( $cachedir ) )
{
mkdir( $cachedir );
}
$ckfile = str_replace( $cdir, "", $filename ).substr( md5( $filename ), 0, 16 ).".inc";
$ckfullfile = $cachedir."/".$ckfile;
$ckfullfile_t = $cachedir."/".$ckfile.".txt";
$this->CacheFile = $ckfullfile;
$this->TempMkTime = filemtime( $filename );
if ( file_exists( $ckfullfile ) )
{
}
if ( !file_exists( $ckfullfile_t ) )
{
return FALSE;
}
$fp = fopen( $ckfullfile_t, "r" );
$time_info = trim( fgets( $fp, 64 ) );
fclose( $fp );
if ( $time_info != $this->TempMkTime )
{
return FALSE;
}
include( $this->CacheFile );
if ( isset( $z ) && is_array( $z ) )
{
foreach ( $z as $k => $v )
{
$this->Count++;
( );
$ctag = new MyTag( );
( );
$ctag->CAttribute = new MyAttribute( );
$ctag->IsReplace = FALSE;
$ctag->TagName = $v[0];
$ctag->InnerText = $v[1];
$ctag->StartPos = $v[2];
$ctag->EndPos = $v[3];
$ctag->TagValue = "";
$ctag->TagID = $k;
if ( isset( $v[4] ) && is_array( $v[4] ) )
{
$i = 0;
foreach ( $v[4] as $k => $v )
{
$ctag->CAttribute++"Count";
$ctag->CAttribute->Items[$k] = $v;
}
}
$this->CTags[$this->Count] = $ctag;
}
return TRUE;
}
$this->CTags = "";
$this->Count = -1;
return TRUE;
}
public function SaveCache( )
{
$fp = fopen( $this->CacheFile.".txt", "w" );
fwrite( $fp, $this->TempMkTime."\n" );
fclose( $fp );
$fp = fopen( $this->CacheFile, "w" );
flock( $fp, 3 );
fwrite( $fp, "<?php\r\n" );
if ( is_array( $this->CTags ) )
{
foreach ( $this->CTags as $tid => $ctag )
{
$arrayValue = "Array(\"".$ctag->TagName."\",";
$arrayValue .= "\"".str_replace( "\$", "\\\$", str_replace( "\r", "\\r", str_replace( "\n", "\\n", str_replace( "\"", "\\\"", str_replace( "\\", "\\\\", $ctag->InnerText ) ) ) ) )."\"";
$arrayValue .= ",".$ctag->StartPos.",{$ctag->EndPos});";
fwrite( $fp, "\$z[".$tid."]={$arrayValue}\n" );
if ( is_array( $ctag->CAttribute->Items ) )
{
foreach ( $ctag->CAttribute->Items as $k => $v )
{
$v = str_replace( "\\", "\\\\", $v );
$v = str_replace( "\"", "\\\"", $v );
$v = str_replace( "\$", "\\\$", $v );
$k = trim( str_replace( "'", "", $k ) );
if ( $k == "" || !( $k != "tagname" ) )
{
fwrite( $fp, "\$z[".$tid."][4]['{$k}']=\"{$v}\";\n" );
}
}
}
}
}
fwrite( $fp, "\n?>" );
fclose( $fp );
}
public function Check( $path, $ds = DIRECTORY_SEPARATOR )
{
if ( preg_match( "#.php\$#", $path ) )
{
exit( "Error:not allowed tpl type!" );
}
$path = $this->clean( $path );
if ( strpos( $path, $this->clean( APP_ROOT ) ) !== 0 )
{
exit( "Error:check Snooping out of bounds @ ".$path );
}
return $path;
}
public function Clean( $path, $ds = DIRECTORY_SEPARATOR )
{
$path = trim( $path );
if ( empty( $path ) )
{
$path = APP_ROOT;
return $path;
}
$path = preg_replace( "#[/\\\\]+#", $ds, $path );
return $path;
}
public function LoadTemplate( $filename )
{
$filename = $this->Check( $filename );
$this->SetDefault( );
if ( !file_exists( $filename ) )
{
$this->SourceString = " ".$filename." Not Found! ";
$this->ParseTemplet( );
}
else
{
$fp = @fopen( $filename, "r" );
while ( $line = fgets( $fp, 2048 ) )
{
$this->SourceString .= $line;
}
fclose( $fp );
if ( $this->LoadCache( $filename ) )
{
return "";
}
$this->ParseTemplet( );
}
}
public function LoadTemplet( $filename )
{
$this->LoadTemplate( $filename );
}
public function LoadFile( $filename )
{
$this->LoadTemplate( $filename );
}
public function LoadSource( $str )
{
$filename = APP_ROOT."/Cache/".md5( $str ).".inc";
if ( !is_dir( APP_ROOT."/Cache/" ) )
{
mkdir( APP_ROOT."/Cache/" );
}
if ( !is_file( $filename ) )
{
file_put_contents( $filename, $str );
}
$this->LoadTemplate( $filename );
}
public function LoadString( $str )
{
$this->LoadSource( $str );
}
public function GetTagID( $str )
{
if ( $this->Count == -1 )
{
return -1;
}
if ( $this->CharToLow )
{
$str = strtolower( $str );
}
foreach ( $this->CTags as $id => $CTag )
{
if ( !( $CTag->TagName == $str ) && $CTag->IsReplace )
{
continue;
}
return $id;
}
return -1;
}
public function GetTag( $str )
{
if ( $this->Count == -1 )
{
return "";
}
if ( $this->CharToLow )
{
$str = strtolower( $str );
}
foreach ( $this->CTags as $id => $CTag )
{
if ( !( $CTag->TagName == $str ) && $CTag->IsReplace )
{
continue;
}
return $CTag;
}
return "";
}
public function GetTagByName( $str )
{
return $this->GetTag( $str );
}
public function GetTagByID( $id )
{
if ( isset( $this->CTags[$id] ) )
{
return $this->CTags[$id];
}
return "";
}
public function AssignVar( $vname, $vvalue )
{
if ( !isset( $_sys_globals['define'] ) )
{
$_sys_globals['define'] = "yes";
}
$_sys_globals[$vname] = $vvalue;
}
public function Assign( $i, $str, $runfunc = TRUE )
{
if ( isset( $this->CTags[$i] ) )
{
$this->CTags[$i]->IsReplace = TRUE;
$this->CTags[$i]->TagValue = $str;
if ( $this->CTags[$i]->GetAtt( "function" ) != "" && $runfunc )
{
$this->CTags[$i]->TagValue = $this->EvalFunc( $str, $this->CTags[$i]->GetAtt( "function" ), $this->CTags[$i] );
}
}
}
public function AssignName( $tagname, $str )
{
foreach ( $this->CTags as $id => $CTag )
{
if ( $CTag->TagName == $tagname )
{
$this->Assign( $id, $str );
}
}
}
public function AssignSysTag( )
{
global $_sys_globals;
$i = 0;
for ( ; $i <= $this->Count; ++$i )
{
$CTag = $this->CTags[$i];
$str = "";
if ( $CTag->TagName == "global" )
{
$str = $this->GetGlobals( $CTag->GetAtt( "name" ) );
if ( $this->CTags[$i]->GetAtt( "function" ) != "" )
{
$str = $this->EvalFunc( $str, $this->CTags[$i]->GetAtt( "function" ), $this->CTags[$i] );
}
$this->CTags[$i]->IsReplace = TRUE;
$this->CTags[$i]->TagValue = $str;
}
else if ( $CTag->TagName == "foreach" )
{
$arr = $this->CTags[$i]->GetAtt( "array" );
if ( isset( $GLOBALS[$arr] ) )
{
foreach ( $GLOBALS['GLOBALS'][$arr] as $k => $v )
{
$istr = "";
$istr .= preg_replace( "/\\[field:key([\r\n\t\\f ]+)\\/\\]/is", $k, $this->CTags[$i]->InnerText );
$str .= preg_replace( "/\\[field:value([\r\n\t\\f ]+)\\/\\]/is", $v, $istr );
}
}
$this->CTags[$i]->IsReplace = TRUE;
$this->CTags[$i]->TagValue = $str;
}
else if ( $CTag->TagName == "var" )
{
$vname = $this->CTags[$i]->GetAtt( "name" );
if ( $vname == "" )
{
$str = "";
}
else
{
if ( $this->CTags[$i]->GetAtt( "value" ) != "" )
{
$_vars[$vname] = $this->CTags[$i]->GetAtt( "value" );
}
else
{
$str = isset( $_vars[$vname] ) ? $_vars[$vname] : "";
}
}
$this->CTags[$i]->IsReplace = TRUE;
$this->CTags[$i]->TagValue = $str;
}
if ( $CTag->GetAtt( "runphp" ) == "yes" )
{
$this->RunPHP( $CTag, $i );
}
if ( is_array( $this->CTags[$i]->TagValue ) )
{
$this->CTags[$i]->TagValue = "array";
}
}
}
public function RunPHP( &$refObj, $i )
{
$MyMeValue = $phpcode = "";
if ( $refObj->GetAtt( "source" ) == "value" )
{
$phpcode = $this->CTags[$i]->TagValue;
}
else
{
$MyMeValue = $this->CTags[$i]->TagValue;
$phpcode = $refObj->GetInnerText( );
}
$phpcode = preg_replace( "/'@me'|\"@me\"|@me/i", "\$MyMeValue", $phpcode );
@eval( $phpcode );
$this->CTags[$i]->TagValue = $MyMeValue;
$this->CTags[$i]->IsReplace = TRUE;
}
public function GetResultNP( )
{
$ResultString = "";
if ( $this->Count == -1 )
{
return $this->SourceString;
}
$this->AssignSysTag( );
$nextTagEnd = 0;
$strok = "";
$i = 0;
for ( ; $i <= $this->Count; ++$i )
{
if ( $this->CTags[$i]->GetValue( ) != "" )
{
if ( $this->CTags[$i]->GetValue( ) == "#@Delete@#" )
{
$this->CTags[$i]->TagValue = "";
}
$ResultString .= substr( $this->SourceString, $nextTagEnd, $this->CTags[$i]->StartPos - $nextTagEnd );
$ResultString .= $this->CTags[$i]->GetValue( );
$nextTagEnd = $this->CTags[$i]->EndPos;
}
}
$slen = strlen( $this->SourceString );
if ( $nextTagEnd < $slen )
{
$ResultString .= substr( $this->SourceString, $nextTagEnd, $slen - $nextTagEnd );
}
return $ResultString;
}
public function GetResult( )
{
$ResultString = "";
if ( $this->Count == -1 )
{
return $this->SourceString;
}
$this->AssignSysTag( );
$nextTagEnd = 0;
$strok = "";
$i = 0;
for ( ; $i <= $this->Count; ++$i )
{
$ResultString .= substr( $this->SourceString, $nextTagEnd, $this->CTags[$i]->StartPos - $nextTagEnd );
$ResultString .= $this->CTags[$i]->GetValue( );
$nextTagEnd = $this->CTags[$i]->EndPos;
}
$slen = strlen( $this->SourceString );
if ( $nextTagEnd < $slen )
{
$ResultString .= substr( $this->SourceString, $nextTagEnd, $slen - $nextTagEnd );
}
return $ResultString;
}
public function Display( )
{
echo $this->GetResult( );
}
public function SaveTo( $filename )
{
if ( !( $fp = @fopen( $filename, "w" ) ) )
{
exit( "MyTag Engine Create File False" );
}
fwrite( $fp, $this->GetResult( ) );
fclose( $fp );
}
public function ParseTemplet( )
{
$TagStartWord = $this->TagStartWord;
$TagEndWord = $this->TagEndWord;
$sPos = 0;
$ePos = 0;
$FullTagStartWord = $TagStartWord.$this->NameSpace.":";
$sTagEndWord = $TagStartWord."/".$this->NameSpace.":";
$eTagEndWord = "/".$TagEndWord;
$tsLen = strlen( $FullTagStartWord );
$sourceLen = strlen( $this->SourceString );
if ( $sourceLen <= $tsLen + 3 )
{
return;
}
( );
$cAtt = new MyAttributeParse( );
$cAtt->charToLow = $this->CharToLow;
$i = 0;
for ( ; $i < $sourceLen; ++$i )
{
$tTagName = "";
if ( 0 <= $i - 1 )
{
$ss = $i - 1;
}
else
{
$ss = 0;
}
$sPos = strpos( $this->SourceString, $FullTagStartWord, $ss );
$isTag = $sPos;
if ( $i == 0 )
{
$headerTag = substr( $this->SourceString, 0, strlen( $FullTagStartWord ) );
if ( $headerTag == $FullTagStartWord )
{
$isTag = TRUE;
$sPos = 0;
}
}
if ( $isTag === FALSE )
{
break;
}
$j = $sPos + $tsLen;
for ( ; $j < $sPos + $tsLen + $this->TagMaxLen; ++$j )
{
if ( $sourceLen - 1 < $j )
{
break;
}
if ( !preg_match( "/[\\/ \t\r\n]/", $this->SourceString[$j] ) )
{
if ( $this->SourceString )
{
break;
break;
}
}
else
{
break;
}
$tTagName .= $this->SourceString[$j];
}
if ( $tTagName != "" )
{
$i = $sPos + $tsLen;
$endPos = -1;
$fullTagEndWordThis = $sTagEndWord.$tTagName.$TagEndWord;
$e1 = strpos( $this->SourceString, $eTagEndWord, $i );
$e2 = strpos( $this->SourceString, $FullTagStartWord, $i );
$e3 = strpos( $this->SourceString, $fullTagEndWordThis, $i );
$e1 = trim( $e1 );
$e2 = trim( $e2 );
$e3 = trim( $e3 );
$e1 = $e1 == "" ? "-1" : $e1;
$e2 = $e2 == "" ? "-1" : $e2;
$e3 = $e3 == "" ? "-1" : $e3;
if ( $e3 == -1 )
{
$endPos = $e1;
$elen = $endPos + strlen( $eTagEndWord );
}
else if ( $e1 == -1 )
{
$endPos = $e3;
$elen = $endPos + strlen( $fullTagEndWordThis );
}
else if ( $e1 < $e2 && $e1 < $e3 )
{
$endPos = $e1;
$elen = $endPos + strlen( $eTagEndWord );
}
else
{
$endPos = $e3;
$elen = $endPos + strlen( $fullTagEndWordThis );
}
if ( $endPos == -1 )
{
echo "Tag Character postion ";
echo $sPos;
echo ", '";
echo $tTagName;
echo "' Error!<br />\r\n";
break;
}
else
{
$i = $elen;
$ePos = $endPos;
$attStr = "";
$innerText = "";
$startInner = 0;
$j = $sPos + $tsLen;
for ( ; $j < $ePos; ++$j )
{
if ( $startInner == 0 && $this->SourceString[$j] == $TagEndWord && $this->SourceString[$j - 1] != "\\" )
{
$startInner = 1;
}
else if ( $startInner == 0 )
{
$attStr .= $this->SourceString[$j];
}
else
{
$innerText .= $this->SourceString[$j];
}
}
$cAtt->SetSource( $attStr );
if ( !( $cAtt->cAttributes->GetTagName( ) != "" ) )
{
continue;
}
$this->Count++;
( );
$CDTag = new MyTag( );
$CDTag->TagName = $cAtt->cAttributes->GetTagName( );
$CDTag->StartPos = $sPos;
$CDTag->EndPos = $i;
$CDTag->CAttribute = $cAtt->cAttributes;
$CDTag->IsReplace = FALSE;
$CDTag->TagID = $this->Count;
$CDTag->InnerText = $innerText;
$this->CTags[$this->Count] = $CDTag;
}
}
else
{
$i = $sPos + $tsLen;
}
break;
}
if ( $this->IsCache )
{
$this->SaveCache( );
}
}
public function EvalFunc( $fieldvalue, $functionname, &$refObj )
{
$MyFieldValue = $fieldvalue;
$functionname = str_replace( "{\"", "[\"", $functionname );
$functionname = str_replace( "\"}", "\"]", $functionname );
$functionname = preg_replace( "/'@me'|\"@me\"|@me/i", "\$MyFieldValue", $functionname );
$functionname = "\$MyFieldValue = ".$functionname;
@eval( $functionname.";" );
if ( empty( $MyFieldValue ) )
{
return "";
}
return $MyFieldValue;
}
public function GetGlobals( $varname )
{
$varname = trim( $varname );
if ( $varname == "dbuserpwd" || $varname == "cfg_dbpwd" )
{
return "";
}
if ( isset( $GLOBALS[$varname] ) )
{
return $GLOBALS[$varname];
}
return "";
}
}
class MyAttribute
{
public $Count = -1;
public $Items = "";
public function GetAtt( $str )
{
if ( $str == "" )
{
return "";
}
if ( isset( $this->Items[$str] ) )
{
return $this->Items[$str];
}
return "";
}
public function GetAttribute( $str )
{
return $this->GetAtt( $str );
}
public function IsAttribute( $str )
{
if ( isset( $this->Items[$str] ) )
{
return TRUE;
}
return FALSE;
}
public function GetTagName( )
{
return $this->GetAtt( "tagname" );
}
public function GetCount( )
{
return $this->Count + 1;
}
}
class MyAttributeParse
{
public $sourceString = "";
public $sourceMaxSize = 2048;
public $cAttributes = "";
public $charToLow = TRUE;
public function SetSource( $str = "" )
{
( );
$this->cAttributes = new MyAttribute( );
$strLen = 0;
$this->sourceString = trim( preg_replace( "/[ \r\n\t]{1,}/", " ", $str ) );
$this->sourceString = str_replace( "\\]", "]", $this->sourceString );
$this->sourceString = str_replace( "[", "[", $this->sourceString );
$strLen = strlen( $this->sourceString );
if ( 0 < $strLen && $strLen <= $this->sourceMaxSize )
{
$this->ParseAttribute( );
}
}
public function ParseAttribute( )
{
$d = "";
$tmpatt = "";
$tmpvalue = "";
$startdd = -1;
$ddtag = "";
$hasAttribute = FALSE;
$strLen = strlen( $this->sourceString );
$i = 0;
for ( ; $i < $strLen; ++$i )
{
if ( $this->sourceString[$i] == " " )
{
$this->cAttributes++"Count";
$tmpvalues = explode( ".", $tmpvalue );
$this->cAttributes->Items['tagname'] = $this->charToLow ? strtolower( $tmpvalues[0] ) : $tmpvalues[0];
if ( isset( $tmpvalues[1] ) && $tmpvalues[1] != "" )
{
$this->cAttributes->Items['name'] = $tmpvalues[1];
}
$tmpvalue = "";
$hasAttribute = TRUE;
}
else
{
$tmpvalue .= $this->sourceString[$i];
}
}
if ( !$hasAttribute )
{
$this->cAttributes++"Count";
$tmpvalues = explode( ".", $tmpvalue );
$this->cAttributes->Items['tagname'] = $this->charToLow ? strtolower( $tmpvalues[0] ) : $tmpvalues[0];
if ( isset( $tmpvalues[1] ) && $tmpvalues[1] != "" )
{
$this->cAttributes->Items['name'] = $tmpvalues[1];
}
}
else
{
$tmpvalue = "";
for ( ; $i < $strLen; default :
switch ( $d )
{
++$i )
{
$d = $this->sourceString[$i];
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 ) )
{
break;
}
case " " :
case "\"" :
$ddtag = "\"";
$startdd = 1;
continue;
case "'" :
$ddtag = "'";
$startdd = 1;
continue;
$tmpvalue .= $d;
$ddtag = " ";
$startdd = 1;
continue;
}
}
if ( $startdd == 1 )
{
if ( $d == $ddtag && isset( $this->sourceString[$i - 1] ) && $this->sourceString[$i - 1] != "\" )
{
$this->cAttributes++"Count";
$this->cAttributes->Items[$tmpatt] = trim( $tmpvalue );
$tmpatt = "";
$tmpvalue = "";
$startdd = -1;
}
else
{
$tmpvalue .= $d;
}
}
}
if ( $tmpatt != "" )
{
$this->cAttributes++"Count";
$this->cAttributes->Items[$tmpatt] = trim( $tmpvalue );
}
}
}
}
?>
报错已经很清楚了,mytag.class.php,155行,括号不匹配。
PHP Parse error: syntax error, unexpected ')' in D:\phpEnv\www\720\App\Lib\Class\mytag.class.php on line 155
楼上回答已经OK了,建议仔细看报错提示,根据提示解决问题
在这个MyTagParse类的LoadCache函数中的foreach ( $z as $k => $v )循环中,大概在155行左右吧。话说,楼主你都不用ide进行编写吗?这些明显的错误,在IDE中都会显示出来的。
哈哈,你这个文件是zend解密出来的吧?!!!!