Last active
April 5, 2019 11:17
-
-
Save isauravmanitripathi/7c366b628d9059570759f7d512b591a4 to your computer and use it in GitHub Desktop.
output buffering in php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ob_start(); | |
print "Hello First!\n"; | |
ob_end_flush(); | |
ob_start(); | |
print "Hello Second!\n"; | |
ob_end_clean(); | |
ob_start(); | |
print "Hello Third\n"; | |
// reusing buffers | |
ob_start(); | |
print "Hello First!\n" | |
ob_flush(); | |
print "Hello Second!\n"; | |
ob_clean(); | |
print "Hello Third!\n"; | |
//stacking buffer | |
ob_start(); | |
print "Hello First!\n"; | |
ob_start(); | |
print "Hello Second!\n"; | |
ob_clean(); | |
// flushed stacked buffer | |
ob_start(); | |
print "In first buffer\n"; | |
ob_start(); | |
print "In second buffer\n"; | |
ob_end_flush(); | |
print "In first buffer\n"; | |
ob_end_flush; | |
the output will be the following: | |
In first buffer | |
In second buffer | |
In first buffer | |
ob_start() | |
print "in first buffer\n"; | |
ob_start(); | |
print "In second buffer\n"; | |
print "In first buffer\n"; | |
ob_end_clean(); | |
// reading buffers | |
$result = mysql_query("SELECT * FROM Employeetable WHERE ID = 55;"); | |
while ($row = mysql_fetch_assoc($result)) { | |
extract($row); | |
print "Some info A: $SomeInforA\n"; | |
print "Some info B: $SomeInforB\n"; | |
print "Some info C: $SomeInforC\n"; | |
//.....[snip].... | |
print "Some infor Z: $SomeInfoZ\n"; | |
} | |
// this code end with data on the screen, if you want it on a file then use this | |
ob_start() | |
$result = mysql_query("SELECT * FROM EmployeeTable WHERE ID = 55;"); | |
while ($row = mysql_fetch_assoc($result)) { | |
extract($row); | |
print "Some info A: $SomeInforA\n"; | |
print "Some info B: $SomeInforB\n"; | |
print "Some info C: $SomeInforC\n"; | |
//.....[snip].... | |
print "Some infor Z: $SomeInfoZ\n"; | |
} | |
$output = ob_get_contents(); | |
ob_end_clean(); | |
file_put_contents("employee.txt", $output); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment