note 99936 added to function.preg-replace

From: Date: Thu, 16 Sep 2010 03:50:18 +0000
Subject: note 99936 added to function.preg-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-172620@lists.php.net to get a copy of this message
If you want to use the dollar sign and immediately a number, you need escape the dollar sign. For example: <?php $foo = 'I got $$$$$10'; $bar = 'No it\'s $2'; $foo = preg_replace('/.+/', $bar, $foo); echo $foo; // returns No it's ?> The reason is that it is making a back reference of a second subpattern. Check this, for more info http://www.php.net/manual/en/regexp.reference.back-references.php If you want that expression to work, you need to escape the dollar sign: <?php $foo = 'I got $$$$$10'; $bar = 'No it\'s \$2'; $foo = preg_replace('/.+/', $bar, $foo); echo $foo; // returns No it's $2 ?> ---- Server IP: 69.147.83.197 Probable Submitter: 201.226.202.7 ---- Manual Page -- http://www.php.net/manual/en/function.preg-replace.php Edit -- https://master.php.net/note/edit/99936 Del: integrated -- https://master.php.net/note/delete/99936/integrated Del: useless -- https://master.php.net/note/delete/99936/useless Del: bad code -- https://master.php.net/note/delete/99936/bad+code Del: spam -- https://master.php.net/note/delete/99936/spam Del: non-english -- https://master.php.net/note/delete/99936/non-english Del: in docs -- https://master.php.net/note/delete/99936/in+docs Del: other reasons-- https://master.php.net/note/delete/99936 Reject -- https://master.php.net/note/reject/99936 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#172620) next »