2013-05-12 152 views
1

我读谷歌Analytics(分析)API文档,发现我从来没有见过一个语法/前使用:HTML标记:<<< HTML

<script> 
<?php 
<<<HTML 
    cxApi.setChosenVariation(
    $chosenVariation,    // The index of the variation shown to the visitor 
    $experimentId     // The id of the experiment the user has been exposed to 
); 
HTML; 
?> 
</script> 

是什么<<<HTML做的,这是什么叫什么?

+1

称为[Heredoc](http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc)。 – Rikesh 2013-05-12 15:37:38

+1

[参考 - 这个符号在PHP中的含义是什么?](http://stackoverflow.com/q/3737139) – mario 2013-05-12 15:44:25

+0

@mario谢谢!棒极了! – 2013-05-12 15:45:26

回答

3

也就是说PHP的heredoc。基本上,它的工作原理是这样的:

<div> 
<?php 
echo <<<EOL 
Write stuff here, 
no need to worry about double " quotes or single ' quotes 
Just write on. 
When done end it like this: 
EOL; 
?> 
</div> 
+1

谢谢!那么'EOL'和'HTML'有什么区别?我要阅读文档(可能也回答我自己的问题) – 2013-05-12 15:43:31

+1

没有区别,这是你的选择的话。当然,它有一些限制和规则,例如结尾的EOL;必须以分号结尾,并且是行中唯一的东西,前后都没有。阅读文档以更好地理解。这并没有那么有用,但是如果你不想逃避各种引号,我认为这对大文本很有用。 – casraf 2013-05-12 15:45:41

3

其所谓的定界符。您可以在PHP站点here上查看它。

+2

Oi在这个网站上的每个人都张贴过快;) – 2013-05-12 15:39:44