0

I am trying to include some javascript for the google analytics ecommerce tracking.

In the example code I see something like this, in which I have replaced the variables with my own.

<?php
 function getTransactionJs(&$order) {
        return <<<HTML
        ga('ecommerce:addTransaction', {
          'id': '{$order->ord_order_numner}',
          'affiliation': 'Marcella',
          'revenue': '{$order->total_payment}',
          'shipping': '0',
          'tax': '0'
        });
        HTML;
    }


echo getTransactionJs($order);
 ?>

However I met with a syntax error. May I ask what is the meaning of

return <<<HTML

Thanks in advance!

Eike Pierstorff
  • 31,996
  • 4
  • 43
  • 62
kkh
  • 4,799
  • 13
  • 45
  • 73
  • 2
    Heredoc: http://www.php.net/manual/de/language.types.string.php#language.types.string.syntax.heredoc. Btw. this is a question about PHP syntax, not Google Analytics, so the tag is somewhat misleading. – Eike Pierstorff Aug 06 '13 at 07:32
  • 2
    @EikePierstorff that'd be an answer – eis Aug 06 '13 at 07:39

3 Answers3

1

It's a way to define a string on multiple lines. Your string begin juste after the <<<HTML and ends at HTML; The HTML word can be replaced by whatever you want.

See Heredoc syntax.

Maxime Lorant
  • 34,607
  • 19
  • 87
  • 97
0

It’s PHP’s Heredoc syntax. I’m not a fan of it though.

Martin Bean
  • 38,379
  • 25
  • 128
  • 201
0

As suggested read the manual, but consider not to use this kind of syntax.

To make your life easier - in most cases the problem is with text indenting.

HTML;

Must be at the start of the line not indented!

Sergei Beregov
  • 738
  • 7
  • 19