| Website PHP - Output Control | | Print | |

Output Control - Output Control functions allow you to control when output is sent from the script. This can be useful in several different situations, especially if you need to send headers to the browser after your script has began outputting data. The Output Control functions do not affect headers sent using header() or setcookie(), only functions such as echo() and data between blocks of PHP code.
PHP is embedded inside HTML in code islands that start with <?php and end with ?>, but you can reverse this by writing your whole script as one big PHP code island and printing HTML as necessary. Going back to the example shown previously, PHP code can look almost identical to the Perl code by printing the HTML from inside our PHP code:
<?php
print "<html>\n";
print "<body>\n";
print "<p>Welcome, $Name</p>\n";
print "</body>\n";
print "</html>\n";
?>
The print( ) function outputs the text enclosed in quotation marks to the client. "\n" means "start new line in the output " and it serves as a "pretty printer"something that makes the output look more attractive.
PHP also has powerful output buffering that further increases your control over the output flow. An output buffer can be thought of as a place where you can queue up content for outputting. Once you start a buffer, any output is automatically put into that buffer and not seen unless the buffer is closed and flushed.
The advantage to this output buffering is twofold. First, it allows you to clean the buffer if you decide that the content it holds is no longer needed. When a buffer is cleaned, all its stored output is deleted as if it were never there, and the output for that buffer is started from scratch.
Second, output buffering allows you to break the traditional ordering of web pagesthat of headers first and content later. Owing to the fact that you queue up all your output, you can send content first, then headers, then more content, then finally flush the buffer. PHP internally rearranges the buffer so that headers come before content.
Read More PHP:PHP - Functions | PHP - Including Other Files
| PHP - Comments
Tutorial | PHP -
Example Whitespace | PHP
- Variables of PHP | PHP
- Basics of PHP | PHP
Abnormal Script | PHP
- Output Control
Links to this article:"PHP - Output Control"
| Users' Comments (0) |
|
No comment posted






