【问题标题】:syntax error, unexpected T_STRING, expecting ',' or ';'” [duplicate]语法错误,意外的 T_STRING,期待 ',' 或 ';'” [重复]
【发布时间】:2015-10-20 23:11:24
【问题描述】:
echo '<a href="'. $site_url .'" onclick=" window.open('. $refferal_url .'); ">';

结果

<a href="http://example.com/" onclick=" window.open(http://example.com/some-url/); ">

问题是我无法在http://example.com/some-url/ 前后加上单引号

因为我总是得到错误。

我该怎么做?

【问题讨论】:

标签: php error-handling single-quotes


【解决方案1】:

您必须转义单引号,因为它们位于单引号字符串中。在需要单引号的地方添加\'

例子:

echo '<a href="'. $site_url .'" onclick=" window.open(\''. $refferal_url .'\'); ">';

顺便说一句,“推荐”有两个rs,而不是两个fs。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-05-26
    • 1970-01-01
    • 2017-06-20
    • 1970-01-01
    • 2013-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多