PHP  "explicit" echo feature

Posted on 2008-11-15
Medium Priority
Last Modified: 2012-05-05
HTML code inside a .PHP file gets conveyed to the output stream without the need for echo statements.
This works nicely in while loop contexts (for instance), such that the php code  loop structure envelopes HTML code and no echo is needed.
 <? while ...  {   // begin loop  ?>
    HTML code
 <?    }// end loop  ?>

1. Where is this documented
2. Does this work in the context of functions too  (as opposed to the above being just inline mainline code?

Question by:willsherwood
LVL 143

Accepted Solution

Guy Hengel [angelIII / a3] earned 1000 total points
ID: 22968741
>1. Where is this documented
in the docs, "first page", at least almost:

>2. Does this work in the context of functions too
LVL 34

Assisted Solution

by:Beverley Portlock
Beverley Portlock earned 1000 total points
ID: 22968751
Well, you could start here http://uk3.php.net/manual/en/tutorial.firstpage.php or http://uk3.php.net/manual/en/getting-started.php

"Does this work in the context of functions too  (as opposed to the above being just inline mainline code?"

It might well do, but it would be very poor programming practice to have "side-effect" out from a function and I've never tried it in several years of writing PHP. Functions should be completely self contained. The best way to proceed with a function that generates HTML is to pass it back as a string or echo out the HTML using the ECHO statement.


Author Closing Comment

ID: 31517160

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
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 Month14 days, 1 hour left to enroll

807 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