note 49025 added to function.eval
| From: | linkage8055 at hotmail dot com | Date: | Fri, 14 Jan 2005 16:35:24 +0000 |
| Subject: | note 49025 added to function.eval | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-83274@lists.php.net to get a copy of this message | ||
modify
function StrToInSide($FStr,$EStr,$Str) // Fast 0.00/s preg_match is 0.0/s this 40000 Lines 1.6MB
{
$SPos = strpos($Str,$FStr);
$EPos = strpos($Str,$EStr);
if( ($Pos->Start>=0) and ($Pos->End>0) )
{
$EPos = ($End-$SPos)+strlen($EStr);
return substr($Str,$SPos,$EPos);
} else return null;
}
function Eval_Str($Contents) //Fast 100 PHP SCRIPT 0.017423/s Size 1MB 30,000 Lines
{
$Matches=UStrToInSide('<?','?>',$Contents);
while(!empty($Matches))
{
$Matches_Str=eregi_replace('(<\?|\?>)','', $Matches);
ob_start();
@eval($Matches_Str);
$Eval_Str = ob_get_contents();
ob_end_clean();
$Contents = str_replace($Matches,$Eval_Str,$Contents);
Matches=UStrToInSide('<?','?>',$Contents);
}
return $Contents;
}
Sample
contents.html
<table>
<tr>
<td>
<? echo 'Hello'; ?>
</td>
</tr>
</table>
Eval_Str.php
$Contents=implode('',file('contents.html'));
echo Eval_Str($Contents);
Output
<table>
<tr>
<td>
Hello
</td>
</tr>
</table>
----
Manual Page -- http://www.php.net/manual/en/function.eval.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+49025
Delete -- http://master.php.net/manage/user-notes.php?action=delete+49025&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+49025&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+49025&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+49025&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+49025&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+49025&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+49025&report=yes
Search -- http://master.php.net/manage/user-notes.php