0

Is it possible to put php code ( NOT ONLY {$SomeVariable} ) inside eof ?

bad syntax but just to get the idea...

$html = <<<EOF
    <!docutype html>
    <html>
    <head>
    <title>{ SOME PHP CODE }</title>
    </head>
    EOF;
nanobash
  • 5,419
  • 7
  • 38
  • 56
  • Sidenote: Use ` ` and not `<!docutype html>` *Plus,* there should not be any spaces before `EOF;` <= Very important. – Funk Forty Niner Mar 20 '14 at 15:23
  • > "there should not be any spaces before EOF;" I spent several hours debugging the pipeline failing issue because I *had* spaces before `EOF`. Thanks man @FunkFortyNiner, you saved me another several hours! – Vardan Aug 15 '23 at 13:11

1 Answers1

1

No, heredoc strings are the same as double-quoted strings with the exception that the double-quote character does not need to be escaped. Variables are expanded in the same way (including complex variables as well as simple variables as in your example). You cannot run code other than this within the string.

I'd recommend reviewing the strings documentation:

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

Also your example is invalid, the closing operator (EOF; in this example) cannot be indented.

Mitch Satchwell
  • 4,770
  • 2
  • 24
  • 31