• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Line breaks in javascript

Hi all,
Im having trouble with line breaks messing up my javascript with unterminated string errors. The string in question is being pulled directly from the database and echo'd into my Javascript with php. Is there any way to echo line breaks out as "\n" instead of them being interpreted as line breaks?


[eluser]hagbard Celine[/eluser]
use str_replace before you echo out your string

If you are using double quotes in the echo, PHP will just throw out a line break. Use single quotes and it will print '\n'. You could also try using the HTML character code for \

echo '\n'; - NOT echo "\n";

echo '& #92 ;n';

Got it, Thanks for the help.

I used:
preg_replace("/\n/", '\n', $string);

and it seemed to do the trick.

Great that you got it to work Smile

Always remember that when a string is enclosed in double quotes, PHP will interpret special characters and variables. With single quotes, it just takes what you give it and doesn't interpret anything.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.