简体   繁体   English

如何获取代码行以接受单引号

[英]How to get line of code to accept single quote

Because of a single quote I am receiving a expecting ) after argument list error: 由于单引号,我在参数列表错误后收到期望的):

window.top.stopAudioUpload(1, '43', 'Thorne, Grandma's Goodbye excerpt.m4a');

audioupload.php (line 11, col 54)

My question is how can I get the line of code to accept single quote? 我的问题是如何让代码行接受单引号?

Code: 码:

 <script language="javascript" type="text/javascript">
 window.top.stopAudioUpload(<?php echo $result; ?>, '<?php echo $id; ?>', '<?php echo $_FILES['fileAudio']['name'] ?>');
 </script>  

Try this: 尝试这个:

<script type="text/javascript">
top.stopAudioUpload(
  <?php echo json_encode($result); ?>,
  <?php echo json_encode($id); ?>,
  <?php echo json_encode($_FILES['fileAudio']['name']); ?>
);
</script>

Note the lack of quotes - this is important, because json_encode will add these automatically if needed. 注意缺少引号-这很重要,因为json_encode会在需要时自动添加引号。

尝试\\逃脱字符“祖母,索恩的再见摘录.m4a”

You could try to manually escape your single-quote with a backslash Thorn, Grandma\\'s Goodbye excerpt.m4a or you could use the escape function - see the docs here: 您可以尝试使用反斜杠Thorn, Grandma\\'s Goodbye excerpt.m4a手动转义单引号,也可以使用转义功能-请参见此处的文档:

http://www.php.net/manual/en/function.htmlspecialchars.php http://www.php.net/manual/zh/function.htmlspecialchars.php

Your issue lies here: 您的问题在这里:

window.top.stopAudioUpload(<?php echo $result; ?>, '<?php echo $id; ?>', '<?php echo $_FILES['fileAudio']['name'] ?>');

Changing the single quotes around '<?php echo will fix it. 更改'<?php echo周围的单引号将解决此问题。 So: 所以:

window.top.stopAudioUpload("<?php echo $result; ?>", "<?php echo $id; ?>", "<?php echo $_FILES['fileAudio']['name'] ?>");

You can also use json_encode($_FILES['fileAudio']['name']) . 您还可以使用json_encode($_FILES['fileAudio']['name']) This adds quotes automatically. 这会自动添加引号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM