Closed jszczypk closed 1 year ago
Tested this on onlinephp.io:
<?php
$re = '/\|/m';
$str = 'a|b';
$subst_bad = '\\n';
$subst_good = "\n";
$result_bad = preg_replace($re, $subst_bad, $str);
$result_good = preg_replace($re, $subst_good, $str);
echo "The result of the bad substitution is \"".$result_bad."\"";
echo "\n";
echo "The result of the good substitution is \"".$result_good."\"";
Result:
The result of the bad substitution is "a\nb"
The result of the good substitution is "a
b"
Thank you, I will change the quotes to double quotes for the substitution text.
Bug Description
When trying to add new line character using substitution incorrect code is generated for PHP because substitution string is incorrectly escaped - should be using double quotes instead of single quotes.
Reproduction steps
flavor: PHP (any) function: Substitution regular expression:
\|
test stringa|b
substitution:\n
Preview shows correctly
Generated code
Output of generated code
Expected Outcome
Generated code
Output of generated code