如何在php中使用带括号的单引号和双引号?

时间:2016-11-23 12:18:53

标签: php html

我在使用带有括号的单引号和双引号时遇到问题

$nestedData[] = '<a href="JavaScript:newPopup('loghistory.php?logid='.$row['user_id'].'')"> History('.$countqry.')</a>';

6 个答案:

答案 0 :(得分:4)

您需要转义引号或连接字符串:

$nestedData[] = '<a href="JavaScript:newPopup('loghistory.php?logid='.$row['user_id'].'')"> History('.$countqry.')</a>';
                                              ^ here your string ends

您可以更改为:

$nestedData[] = '<a href="JavaScript:newPopup(\'loghistory.php?logid='.$row['user_id'].'\')"> History('.$countqry.')</a>';

或另一种选择:

$nestedData[] = '<a href="JavaScript:newPopup('. "'loghistory.php?logid='" .$row['user_id']. "'" . ')"> History('. $countqry .')</a>';

答案 1 :(得分:1)

你可以用\单号和双引号转义\ 像这样:

'You\'re'

答案 2 :(得分:1)

$nestedData[] = '<a href="JavaScript:newPopup('loghistory.php?logid='.$row['user_id'].'')"> History('.$countqry.')</a>';

尝试以下代码:

<a href="JavaScript:newPopup("loghistory.php?logid='.$row['user_id'].'')"> History('.$countqry.')</a>

答案 3 :(得分:0)

如果您希望从litteral字符串中输出单个标记,那么您将需要转义该单引号:

$('form#foodForm').on('submit', function(event) {
    event.preventDefault();
    $.ajax({
        url: this.action,
        data: $(this).serialize(),
        succes: function(data) {
            // this is what your view returns which should be either
            // - an html snippet
            // - json (returned via JSONResponse)
        },
        error: ...
    });
});

将输出:

Graeme的例子

答案 4 :(得分:0)

$nestedData[] = "<a href=\"JavaScript:newPopup('loghistory.php?logid='".$row['user_id']."')"."\"> History('".$countqry."')</a>";

使用\

转义引号

这应该可以解决问题

答案 5 :(得分:0)

$nestedData[] = '<a href="JavaScript:newPopup('".loghistory.php?logid='".$row['user_id']."'."')"> History("'.$countqry.'")</a>';