简体   繁体   English

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

[英]how to use single and double quotes with brackets in php?

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

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

You need to escape the quotes or concat the strings: 您需要转义引号或连接字符串:

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

You can change to: 您可以更改为:

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

Or another option: 或另一个选择:

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

您可以使用\\转义单引号和双引号,如下所示:

'You\'re'
$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>

If you wish to output a single tick from within a litteral string then you will need to escape that single quote: 如果您希望从乱抛垃圾的字符串中输出单个刻度,则需要转义该单个引号:

$a = 'Graeme\'s example';
echo $a;

Will output: 将输出:

Graeme's example 格雷姆的例子

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

Escape the quotes with \\ 用\\转义引号

this should do the trick 这应该可以解决问题

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

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

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