Let’s say I have a string
This $0 is $2 $1. Still, \$$3 is a lot to pay for a puppy.
and an array of replacements
array('puppy', 'cute', 'ridiculously', '1300')
What would be the cleanest way to replace the tokens in the string with the corresponding items in the array, letting me backslash-escape the token character (in this case $)? I also want to replace unmatched tokens with the empty string.
i guess you meant “\$3”, not “\$$3”
btw, did you know that sprintf allows numbered params as well (http://php.net/manual/en/function.sprintf.php example 3)