How to allow PHP echo "\ n" as plain text for javascript and not have "\ n" create a new line?

PHP repeats JavaScript (I use jQuery library) like this:

echo 'var users = $("#add").val().split("\n");';

However, \ n creates a line break in what the script echo looks like and therefore breaks JavaScript. Is there any way around this?
Thank you very much!

+4
source share
3 answers

\n is an escape sequence indicating a new line. Backslashes are the beginning of escape sequences to output a backslash and then write \\ . So you want \\n . Other useful escape sequences include a quote: use \" to put a quote on a line instead of the end of a line.

+5
source
 echo "var users = $(\"#add\").val().split(\"\\n\");"; 
0
source

Not sure If you are looking for this

 echo "<script>alert('Line1\\\\nThis still in Line1')</script>"; 
0
source

All Articles