I am trying to create a hook, so that when the following is found within text:
level,2
It replaces it with $skill_level * $n, with the number after the comma being $n
Here is what I have:
$skill_level = 2;
$row['s_effect'] = "Long string of text that contains level,2."
preg_replace("/level,$n/",$skill_level * $n,$row['s_effect'])
I am getting a result of:
Long string of text that contains 02.
I want a result of:
Long string of text that contains 4.
For some reason it seems the calculation "$skill_level * $n" (2 * 2) is not working.
You need to use
preg_replace_callback