23

我正在尝试创建一个具有三层嵌套引号的 php 变量。如何围绕"tackEvent""downloads""all"和进行第三级"nofilter"?我在那里的双引号不起作用。

  $outputList .= "<a href=files/".$content_file ." onClick='_gaq.push
(["_trackEvent", "downloads", "all", "nofilter"]);' >" . $content_name . 
"</a>";
4

4 回答 4

36

From here:

  • Outer quote = " (This marks the beginning and end of the string)
  • Inner quote = \" (Escaped as to not flag "beginning/end of string")
  • Third-tier quote = ' (Literal quote)
  • Fourth-tier quote = \' (Literal quote that will be generated as an escaped outer quote)
于 2011-09-30T19:03:28.997 回答
2
  • 外报价:"
  • 内部报价: '
  • 三级报价: \"
  • 四级报价: &quot;
于 2017-06-07T20:25:54.490 回答
1
$outputList .= <<<LINK
<a href="files/$content_file" onClick="_gaq.push(['_trackEvent', 'downloads', 'all', 'nofilter']);">$content_name</a>
LINK;

This is using heredoc syntax.

于 2011-09-30T19:02:03.083 回答
1

手册

要指定文字单引号,请使用反斜杠 (\) 对其进行转义。要指定文字反斜杠,请将其加倍 (\\)。

这也适用于双引号中的字符串。

$str = "I am a string with a quote that says, \"I like quotes\"";
于 2011-09-30T18:58:51.083 回答