I have a variable in php
$test = "This is a string
It has multiple lines
there are three total" ;
(Output from a text area)
I want to pass this variable to a javascript function
I have write this in my php file
<?php echo "<script language=javascript>convert('$test');</script>"; ?>
but this makes an error "Unterminated st开发者_运维百科ring literal" How can i solve this issue ??
Try
$test = "This is a string\nIt has multiple lines\nthere are three total";
<script>convert(<?php echo json_encode($test); ?>);</script>
Try this:
$test = str_replace($test, "\n", "\\n");
精彩评论