开发者

Nesting with three levels of quotations

开发者 https://www.devze.com 2023-04-09 10:10 出处:网络
I am trying to create a php variable that has three levels of nested quotes. How do I make a third level around \"tackEvent\", \"downloads\", \"all\", and \"nofilter\"? The double quotes that I have t

I am trying to create a php variable that has three levels of nested quotes. How do I make a third level around "tackEvent", "downloads", "all", and "nofilter"? The double quotes that I have there are not working.

  $outputList .= "<a href=files/".$content_file ." onClick='_gaq.push
(["_trackEvent", "downloads", "all", "nofilter"])开发者_JS百科;' >" . $content_name . 
"</a>";


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)


  • Outer quote: "
  • Inner quote: '
  • Third-tier quote: \"
  • Fourth-tier quote: &quot;


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

This is using heredoc syntax.


From the manual:

To specify a literal single quote, escape it with a backslash (\). To specify a literal backslash, double it (\\).

This applies to strings in double quotes as well.

$str = "I am a string with a quote that says, \"I like quotes\"";
0

精彩评论

暂无评论...
验证码 换一张
取 消