Link to home
Start Free TrialLog in
Avatar of bac3
bac3

asked on

how to use php code in <<<EOT

how to use php code in <<<EOT
EOT;

Is it possible? i only know how to echo a variable, but not write a statement inside (e.g. if else statement)
ASKER CERTIFIED SOLUTION
Avatar of keteracel
keteracel
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Roonaan
Hello bac3,

Does it make sense to have php in your <<<EOT? Is it possible to split your <<<EOT's in multiple parts with the php logic in between?

As alternative you could use output buffering:

ob_start();
echo $something;
$i++;
echo $something_else;

$var = ob_get_clean();

Or store data in a var:
$data = $something;
$i++;
$data .= $something_else;

Regards,

Roonaan
The whole point of the <<<END syntax is that you can write whatever else you want until the
END;

and it WILL NOT BE PRE-PROCESSED :-)

To post any variable data you must END; and continue with your php, or use print() or echo() etc.
Sorry Synthetics, you have that a bit wrong. You CAN have variables within the heredoc syntax. see http://uk.php.net/manual/en/language.types.string.php and in particular the bit which says:

 "When a string is specified in double quotes or with heredoc, variables are parsed within it."

Also, read the question. bac3 was asking if he could put statements within Heredoc blocks. He already knows how to put variables in there.
ahh learn something new every day! but by "variable data" I didn't just mean variables; I meant anything relating to non-static output, i.e. all php code.

Have to see if I can shortcut some of my code with variable heredocs :-D