How do I make a string that was declared using single quotes, evaluate \n
as if it was declared using double quotes?
ie.
echo 'Line1\nLine2'; // Does not split.
echo "Line1\nLine2"; // It splits.
$s = 'A string declared using \n single quotes which I can\'t change...';
echo $s // I need this to have the split at \n
You should just be able to str_replace
them to an actual newline:
$s = str_replace('\n', "\n", $s);
See https://3v4l.org/j0etV
If you're going to be displaying this as HTML, note that you'll also need to run it through nl2br
(or if you're using a templating engine this might already be done for you)
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