note 49020 deleted from function.eval by nlopess
| From: | nlopess@php.net | Date: | Sat, 15 Jan 2005 13:00:04 +0000 |
| Subject: | note 49020 deleted from function.eval by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-83303@lists.php.net to get a copy of this message | ||
Note Submitter: linkage8055 at hotmail dot com
----
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((!empty($SPos)) and (!empty($EPos)))
{
$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_Str);
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>