?
Solved

how to use php code in <<<EOT

Posted on 2007-10-08
5
Medium Priority
?
6,869 Views
Last Modified: 2013-12-13
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)
0
Comment
Question by:bac3
  • 2
  • 2
5 Comments
 
LVL 9

Accepted Solution

by:
keteracel earned 150 total points
ID: 20033422
quick answer.... you can't. You should do all logic and function calls outside of these blocks.
0
 
LVL 49

Expert Comment

by:Roonaan
ID: 20033426
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
0
 
LVL 5

Expert Comment

by:Synthetics
ID: 20036042
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.
0
 
LVL 9

Expert Comment

by:keteracel
ID: 20039364
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.
0
 
LVL 5

Expert Comment

by:Synthetics
ID: 20039766
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
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses
Course of the Month17 days, 7 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question