2013-05-12 253 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