Walter81
Walter81

Reputation: 473

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

Upvotes: 3

Views: 2224

Answers (1)

Valdars
Valdars

Reputation: 863

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

Upvotes: 9

Related Questions