I am trying to print the string of a PHP variable in a Javascript function.Whenever i use a new line in the string that is stored in the PHP variable, I get this error Uncaught SyntaxError while printing it out in a Javascript function.
1 Answer
If you want to declare a string variable across multiple lines, you could use this syntax:
var str = `line 1
line 2
line 3`;
Note the (`) instead of (")/(') double or single quotes. They can't be used to declare multiline string.
Essentially, you will need to write it like this:
jQuery("body").replaceWith(`<?php echo $PHPVARIABLE?>`)
-
Perfectly fixed my issue of taking user input from a textarea! Thank you! Mar 5, 2019 at 2:34