You are here: back slashes and preg_replace's e modifier « PHP Programming Language « IT news, forums, messages
back slashes and preg_replace's e modifier

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация