$fixNum=30;
I have a fixed number variable like the above.
and a string variable like the below.
$myVar='Hello, relativeNum250 I am a boy and relativeNum300 you are a girl';
The 1st relativeNum250 means 7500 which is 30($fixNum)*250.
The 2nd relativeNum300 means 9000 which is 30($fixNum)*300.
So in order to produce, the code below works fine…
$myVar=str_replace('relativeNum250', $fixNum*250, $myVar);
$myVar=str_replace('relativeNum300', $fixNum*300, $myVar);
echo $myVar;
The result of the code above is the following which is my target result.
Hello, 7500 I am a boy and 9000 you are a girl
As the variable $myVar is dynamic, it can be varied like the code below.
[code]$myVar=‘You are a relativeNum100 woman, I am a relativeNum120 man and they are relativeNum360 people’;
$myVar=str_replace(‘relativeNum100’, $fixNum100, $myVar);
$myVar=str_replace(‘relativeNum120’, $fixNum120, $myVar);
$myVar=str_replace(‘relativeNum360’, $fixNum*360, $myVar);
[/code]The result of the code above is the following which is my target result.
You are a 3000 woman, I am a 3600 man and they are 10800 people
I don’t know how many relativeNum is in the string and what is the value of each relativeNum,i.e 100,120,360.
but I know only ‘fixNum=30’ and 3 digit number is followed by each relativeNum.
And I have to find the value of each relativeNum by multifling 30($fixNum)" and the 3 digit which is followed by 'relativeNum.
Can I produce my target result with the dynamic string($myVar) by your help?