Reputation: 55
PHP is echoing JavaScript (I'm using the jQuery library) something like this:
echo 'var users = $("#add").val().split("\n");';
However, the \n is creating a line break in what the echoed script looks like, and therefore breaking the JavaScript. Is there a way to circumvent this?
Many thanks!
Upvotes: 4
Views: 2720
Reputation: 669
Not sure If you looking for this
echo "<script>alert('Line1\\\\nThis still in Line1')</script>";
Upvotes: 0
Reputation: 17329
The \n
is an escape sequence meaning newline. Backslashes are the beginning of escape sequences, to output a backslash then write \\
. So you want \\n
. Other useful escape sequences include the quote: use \"
to put a quote into the string instead of ending the string.
Upvotes: 5