Wednesday 12 December 2018

newline - php convert single quote to double quote for line break character



I have a string coming from a language file containing strings with the text in the current language.



$str = 'blabla\n\nmore blabla';


$str is going to be used in an textarea where the \n must be a linebreak
If I place it inside double quotes this works.




The problem is that $str will always be in single quotes. I've been Googling and searching this site. There are many similar questions, but I didn't manage to find a solution.



How can I convert my single-quoted string (with a literal "\n") to a doublequoted string (where "\n" is converted to a linebreak)?


Answer



$str = str_replace('\n', "\n", $str);


No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...