开发者

How can i pass a string with multiple line to a javascript function?

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");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜