I want to insert a variable inside the EOT but is not working (I am new to php, maybe that's why). This code is part of a script, when I echo $username
alone it shows the real name, but when I put it inside EOT is displaying plain text not the real name..
What am I doing wrong?
$username=getUsername($ID);
echo <<<'EOT'
Some HTML code goes here
Hello $username, welcome back!
Some HTML code goes here
EOT;
So, for example, we could use the string EOT (end of text) for our delimiter, meaning that we can use double quotes and single quotes freely within the body of the text—the string only ends when we type EOT .
Heredoc is one of the ways to store or print a block of text in PHP. The data stored in the heredoc variable is more readable and error-free than other variables for using indentation and newline.
The Embedded OpenType File Format (EOT) was developed by Microsoft to enable TrueType and OpenType fonts to be linked to web pages for download to render the web page with the font the author desired.
The @ symbol is the error control operator ("silence" or "shut-up" operator). It makes PHP suppress any error messages (notice, warning, fatal, etc) generated by the associated expression. It works just like a unary operator, for example, it has a precedence and associativity.
$variable = 'text';
echo <<<EOT
Some {$variable} here
EOT;
You must leave out the single quotes here:
echo <<<'EOT'
This denotes the 'nowdoc' variant, which doesn't interpolate variables.
But you need the original "heredoc" syntax without quotes:
echo <<<EOT
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With