为了账号安全,请及时绑定邮箱和手机立即绑定

PHP wordwrap 数组到 Javascript 返回错误

PHP wordwrap 数组到 Javascript 返回错误

慕容708150 2023-04-14 15:15:42
运行以下代码时出现控制台错误:<?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。哪里有问题?
查看完整描述

1 回答

?
肥皂起泡泡

TA贡献1829条经验 获得超6个赞

正如@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>


查看完整回答
反对 回复 2023-04-14
  • 1 回答
  • 0 关注
  • 86 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信