Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Inserting variable inside EOT

Tags:

variables

php

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;
like image 865
Adrian M. Avatar asked Apr 26 '11 00:04

Adrian M.


People also ask

What does EOT mean in PHP?

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 .

Why use heredoc in PHP?

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.

What is EOT in HTML?

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.

What is the use of symbol in PHP explain with an example?

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.


2 Answers

$variable = 'text';
echo <<<EOT
Some {$variable} here
EOT;
like image 168
s4nch3z Avatar answered Sep 17 '22 17:09

s4nch3z


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
like image 42
mario Avatar answered Sep 17 '22 17:09

mario