by
0
3
503
2
Top 5% !
Popular
Specified
Created
Modified Oct 11, 2017

Published on:

No tags for this snippet yet.
LanguagePHP
SourceGitHub
SourceMyGists

ob flush example

ob flush example: 
ob_flush.php
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/2949862/ob-flush-example?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
<?php /* == ob_end_flush() == Flush (send) the output buffer and turn off output buffering == ob_end_clean() == Clean (erase) the output buffer and turn off output buffering == ob_get_contents() == Return the contents of the output buffer */ # The following two functions result in the same output. function output_some_html_with_var() { ob_start(); ?> <p>This is a paragraph echoed from a variable.</p> <?php $para = ob_get_contents(); ob_end_clean(); echo $para; } function output_some_html_with_end_flush() { ob_start(); ?> <p>This is a paragraph sent with ob_end_flush.</p> <?php ob_end_flush(); } output_some_html_with_var(); output_some_html_with_end_flush(); /* If you want to return the contents of ob_start() you should store ob_get_contents() into a variable, then call ob_end_clean(), and then return the variable. */ function return_some_html_with_var() { ob_start(); ?> <p>This is a paragraph being stored into a variable and returned.</p> <?php $para = ob_get_contents(); ob_end_clean(); return $para; } echo return_some_html_with_var(); echo '<a style="text-decoration:none;" href="http://php.net/manual/en/function.ob-start.php">See the ob_start documentiation for more info</a>';
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus