3

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)?

Walter81
  • 493
  • 2
  • 8
  • 21
  • 1
    Here's a thread which answers your question: http://stackoverflow.com/questions/8309731/interpret-escape-characters-in-single-quoted-string – DiscoInfiltrator Feb 05 '13 at 14:54

1 Answers1

9

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

Valdars
  • 833
  • 6
  • 9