I’m trying to get it once again.
I got a JS var which looks like this:
var test;
Now I write some JS with PHP:
<?php
$phpvar = "a text with
a linebreak";
echo "<script type='text/javascript'>
var test;
test = '" . $phpvar . "';
</script>";
?>
Now, if I run it, it outputs the source as follows:
<script type='text/javascript'>
var test;
test = 'a text with
a linebreak';
</script>
This gives me a JS exception:
ERROR: unterminated string literal
Somehow, JS seems not to recognize that there is a string on more than one line.
How can I realize this if, in the end, the string must have its linebreak again? (So, if all execution finishes, I must have the string including all linebreaks)
Thank you for your help 😉
Try this, if you use a \ at the end of a Javascript line, you can use multiple lines within a string.