php - 如何将多行字符串传递给 javascript 函数?

标签 php javascript

我在php中有一个变量

$test = "This is a string
It has multiple lines
there are three total" ;

(从文本区域输出)

我想将此变量传递给 javascript 函数

我已经把这个写在我的 php 文件里了

<?php echo "<script language=javascript>convert('$test');</script>"; ?>

但这会产生错误“未终止的字符串文字”我该如何解决这个问题??

最佳答案

尝试

$test = "This is a string\nIt has multiple lines\nthere are three total";

关于php - 如何将多行字符串传递给 javascript 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5868800/

相关文章:

php - MySQL 日期时间在 PHP 上回显

PHP - float 精度

javascript - PHP 将数组传递给 SQL 查询

javascript - 将 javascript 方法参数作为对象文字传递

javascript - 构造函数返回什么?

javascript - 如何在 Promise 中使用 requestAnimationFrame

javascript - 每 x 秒从远程服务器重新加载一次图像,而不重新加载整个页面

php - 在 PHP 中上传多个文件并将路径插入到 MySQL

php - require_once : failed to open stream

javascript - 表单验证和 Node JS - 避免厄运金字塔