【问题标题】:How to solve using single quotes within double quotes within the $content = ' '如何解决在 $content = ' ' 内的双引号内使用单引号
【发布时间】:2017-07-14 20:25:35
【问题描述】:

由于双引号内的单引号引起错误,并且所有内容都在 $content 变量的单引号内。请问这个怎么解决?

$content = '

setTimeout("finishAjax('usernameResult', '"+escape(response)+"')", 400);

';

【问题讨论】:

  • 转义引号
  • $content = "setTimeout(\"finishAjax('usernameResult', 'escape(response)')\", 400)";
  • 您好,Jay,感谢您的回复。但是,它仍然显示错误“ Parse error: syntax error, unexpected 'usernameResult' (T_STRING) in C:\xampp\htdocs\fm-reg\register.php on line 105;”

标签: php double-quotes single-quotes


【解决方案1】:

为了在字符串文字中放置单引号或双引号,您必须先对其进行转义。 PHP 中的转义字符是反斜杠 (\)。

$content = "setTimeout(\"finishAjax('usernameResult', '+escape(response)+')\", 400);";

详细了解转义字符HERE

【讨论】:

    猜你喜欢
    • 2018-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-26
    相关资源
    最近更新 更多