admin管理员组

文章数量:1195282

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.

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.

Share Improve this question asked Aug 13, 2017 at 14:30 Jahidul Haque PathanJahidul Haque Pathan 1552 silver badges12 bronze badges 2
  • 1 Do not post pictures. Paste your code here instead, and show us what you have tried. – Milan Chheda Commented Aug 13, 2017 at 14:30
  • ok sir. i am new in stackoverflow.next time i will paste my code.Thanks – Jahidul Haque Pathan Commented Aug 13, 2017 at 14:32
Add a comment  | 

1 Answer 1

Reset to default 30

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

本文标签: javascriptUncaught SyntaxError Invalid or unexpected token for new lineStack Overflow