I have a number variable "$myNumber" which is like the above.
$myVar='myVar is plus5 which is '.$myNumber.'+5
myVar is plus10 which is '.$myNumber.'+10
myVar is plus20 which is '.$myNumber.'+20';
I like to replace the text plus5 to 105, the text plus10 to 110 and the text plus20 to 120.
So my target result will be like the following.
How can I get $myTarget_result from $myVar?
$myTarget_result='myVar is 105 which is 100+5
'myVar is 110 which is 100+10
myVar is 120 which is 100+20';
Originally Posted by dotJoon
This is assuming you weren't wanting to concatenate the string (like you did with $myNumber)
$myTarget_result = str_replace(array('plus5', 'plus10', 'plus20'), array($myNumber + 5, $myNumber + 10, $myNumber+20), $myTarget_result);
$myVar='myVar is '.($myNumber+5).' which is '.$myNumber.'+5
myVar is '.($myNumber+10).' which is '.$myNumber.'+10
myVar is '.($myNumber+20).' which is '.$myNumber.'+20';