-1

Possible Duplicate:
Is there a reason to use Heredoc in PHP?

I'm new to PHP.

Is it good practice to use something like that?

echo <<< HTML
        <a href="$link" title="$title">$item</a>
HTML;

It does work, but I'm not sure if I'm using it correctly.

Thanks very much...

Community
  • 1
  • 1

2 Answers2

1

It is perfectly fine to use single-quotes, double-quotes, heredoc and nowdoc, depending on what you need (formatting, variables inside, etc.). See more info here.

Shomz
  • 37,421
  • 4
  • 57
  • 85
0

Mixing HTML and PHP in the same file is never a good practice. Separate code and templates by putting them in different files and possibly using a template engine.

However, if you need to put blocks of HTML in a PHP file the heredoc syntax you used in your example is perfectly fine as it avoids the escaping hell you'd have when using regular quotes.

For the various ways of quoting strings have a look at the PHP documentation. It also explains how the various strings behave (e.g. regarding variable interpolation and escape sequences).

ThiefMaster
  • 310,957
  • 84
  • 592
  • 636