Im trying to make a preg-replace pattern to convert the text “orderId” into “order-id”.
$argumentName = "orderId";
$argumentName = preg_replace("/([A-Z])/e", "-strtolower($1)", $argumentName);
echo $argumentName;
The output for this line is “order0d”. Why is this not working?
Since you’re specifying that your replacement-string is an expression, this:
is
'i'(as it should be), and this:is
-'i'(“negative'i'“), which forces the string'i'to be interpreted as a number —0.What you want is
which concatenates the strings
'-'and'i'.