php - preg_replace add "00" after $1 without spaces in Replacement -


im trying add "00" after $1 without spaces in preg_replace replacement.

my code:

$count = null; $returnvalue = preg_replace('/de(.*)y/i', '$1 00', 'delipsumy', -1, $count); 

i want have '$1'.'00' replacement output should be:

lipsum00 (without space)

i tried '$1'.'00' , '$100' doesnt work

any suggestion?

this addressed in method's documentation (emphasis added):

when working replacement pattern backreference followed number (i.e.: placing literal number after matched pattern), cannot use familiar \1 notation backreference. \11, example, confuse preg_replace() since not know whether want \1 backreference followed literal 1, or \11 backreference followed nothing. in case solution use \${1}1. creates isolated $1 backreference, leaving 1 literal.

so replacement pattern '\${1}00'. example:

// output: h__e__ll__o__ w__o__rld echo preg_replace("/([aeiou])/", "__\${1}__", "hello world"); 

see in action: http://codepad.org/orbk5jdw


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -