Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/402.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将unicode php变量传递给javascript_Javascript_Php_Json - Fatal编程技术网

将unicode php变量传递给javascript

将unicode php变量传递给javascript,javascript,php,json,Javascript,Php,Json,我试图将wordpress文章的标题和摘录(波斯语)传递到javascript。下面是.php脚本文件中的代码: function change(){ document.getElementById("link").innerHTML = '<a href="$links[2]">$titles[2]</a>'; document.getElementById("exer").innerHTML = '$excerpts[2

我试图将
wordpress
文章的标题和摘录(波斯语)传递到
javascript
。下面是
.php
脚本文件中的代码:

function change(){
            document.getElementById("link").innerHTML = '<a href="$links[2]">$titles[2]</a>';
            document.getElementById("exer").innerHTML = '$excerpts[2]';
            document.getElementById("img").innerHTML = '$imgs[2]';
}
以下是chrome浏览器中显示的错误(它指的是我向javascript传递的$摘录行):

当我在
php
中使用
json\u encode
转换javascript变量时,错误消失,但所有摘录变量都变成空字符串
“”

我尝试了一些
regex
解决方案来删除不需要的非unicode字符,但它也有同样的问题


任何帮助都将不胜感激。

哦!我在wordpress的函数的输出中发现了一些东西。它在_extract()输出中包含一个换行符。 多亏了,我使用了如下正则表达式:

$excerpts = preg_replace( "/\r|\n/", "", $excerpts );

问题解决了

哦!我在wordpress的函数的输出中发现了一些东西。它在_extract()输出中包含一个换行符。 多亏了,我使用了如下正则表达式:

$excerpts = preg_replace( "/\r|\n/", "", $excerpts );
问题解决了

$excerpts = preg_replace( "/\r|\n/", "", $excerpts );