As I understand, stripslashes should not remove slash from newline character "\n". And all works fine, excepts situation, when I have a newline character in a variable.
$string = '\n\"';
echo stripslashes($string); // n"
But I need in the next output: \n"
.
Thank you in advance.
I think you are mixing double and simple quotes
$bad = '\n\"';
$good = "\n\"";
Using single quote there is no escapement(appart \') also in single quote PHP won't replace PHP variables.
On the other hand the double quote permits using escaped sequence such as \n
, \t
etc...
You can review the documentation and check the differences.
So you meant to write
$string = "\n\"";
echo stripslashes($string); // \n"
Inside single quotes, \n
does not translate to a newline. Use double quotes instead:
$string = "\n\"";
For a better understanding, your current code is equivalent to:
$unwanted_string = "\\n\\\""; // Will be printed as: \n\"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With