|
Posted by yawnmoth on 11/06/05 00:29
Can anyone help me understand the following scripts output?:
<?
echo preg_replace('/.*/e',"sprintf('\\\\\')",'');
?>
The output is \ and this doesn't make a lot of sense to me.
Since \\'s in strings are interpreted as single \'s, the above sprintf
parameter is equal to \\\. The following scripts output confirms this:
<?
echo "sprintf('\\\\\')";
?>
Attempting to run the output of the second script (as done in the next
script), however, results in a syntax error:
<?
echo sprintf('\\\');
?>
The fact that a syntax error would result isn't particurarly surprising
since the last ' is being escaped. What is surprising, however, is
that the last script yields a syntax error whereas the first script
doesn't. Any ideas as to why?
Navigation:
[Reply to this message]
|