What if I want to multiply all numbers by 2? Can this be done with regex replace? Note the $1*2 part that obviously doesn’t work. How would I do this?
$foo = "soup 12 cake 23 pants";
$bar = preg_replace('~(\d+)~', $1*2, $foo);
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You could use
preg_replace_callback: