PHP wordwrap 数组到 Javascript 返回错误

运行以下代码时出现控制台错误:



<?php

$str = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.";

$str = wordwrap($str,30,'\n');

?>


document.write('test' + '\n');

document.write( '<?php echo $str;?>' + '\n' );


</script>

控制台错误:Uncaught SyntaxError: missing ) after argument list。


哪里有问题?


慕容708150
浏览 87回答 1
1回答

肥皂起泡泡

正如@u_mulder 指出的那样,您必须将引号转义'为:<?php    $str = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.";    $str = str_replace("'", "\'", wordwrap($str,30,'\n'));?><script>    document.write('test' + '\n');    document.write( '<?php echo $str;?>' + '\n' );</script>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript