1

我正在阅读 Google Analytics API 文档并注意到我以前从未见过/使用过的语法:

<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,这叫什么?


4

3 回答 3

4

它被称为HEREDOC字符串。来自文档:

http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

于 2013-05-12T15:37:38.683 回答
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>
于 2013-05-12T15:38:05.310 回答
3

它称为heredoc语法。您可以在此处的 PHP 站点上查看它。

于 2013-05-12T15:38:34.183 回答