Turn on output buffering in PHP

Description

The following code shows how to turn on output buffering.

Example


<?php/*from  w w  w  . j  av  a  2  s .co m*/
  //begin output buffering
  ob_start();
?>
<html>
<head>
  <title>ob_start</title>
</head>
<body>
<?php
  print("At this point ");
  print(strlen(ob_get_contents()));
  print(" characters are in the buffer.<br>\n");
?>
  </body>
  </html>
<?php
  //add a test header
  header("X-note: COREPHP");

  //dump the contents
  ob_end_flush();
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Development »




Environment
Error
Hash
Include
Locale
Math
Network
Output
Reflection
PHP Regular Expressions