1

I was reading Google Analytics API documentation and noticed a syntax I've never seen/used before:

<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>

What does <<<HTML do, what's this called?

d-_-b
  • 21,536
  • 40
  • 150
  • 256
  • 1
    Called as [Heredoc](http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc). – Rikesh May 12 '13 at 15:37
  • 1
    [Reference - What does this symbol mean in PHP?](http://stackoverflow.com/q/3737139) – mario May 12 '13 at 15:44

3 Answers3

4

It's called HEREDOC string. From docs:

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

galchen
  • 5,252
  • 3
  • 29
  • 43
3

That is PHP's heredoc. Basically it works like this:

<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>
casraf
  • 21,085
  • 9
  • 56
  • 91
  • 1
    THanks! So what's the difference between `EOL` and `HTML`? I'm off to read the documentation (probably answer my own question too) – d-_-b May 12 '13 at 15:43
  • 1
    No difference, it's your word of choosing. Of course, it has some limitations and rules, for example the ending EOL; has to end with a semicolon and be the only thing in the line, nothing before or after. Read the documentation to understand better. It's not that useful, but I guess it's good for big texts when you don't wanna escape all sorts of quotation marks. – casraf May 12 '13 at 15:45
3

Its called the heredoc syntax. You can check it out on the PHP site here.

Gary
  • 13,303
  • 18
  • 49
  • 71