note 75694 added to function.ob-clean
| From: | lev at taintedthoughts dot com | Date: | Tue, 12 Jun 2007 09:23:42 +0000 |
| Subject: | note 75694 added to function.ob-clean | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-127413@lists.php.net to get a copy of this message | ||
I find this function incredibly useful when manipulating or creating images in php (with GD).
I spent quite a while searching through a large number of included files to find where I had a
undesired space after php's ending tag - as this was causing all my images on the fly to break
due to output already being set. Even more annoying was that this was not caught not php's
error reporting so there was no reference to the problem line(s) in my log file. I don't know
why error reporting wouldn't catch this since it was set to accept warnings, and the same thing
had been caught in the past.
Nevertheless, I never did find the line(s) that were adding extra spaces or new lines before my
images were being generated, but what I did instead was add this handy function right before my
image manipulation code and right after the include/require code.
For example:
<?php
// require some external library files
require ("lib/somelibrary.php");
require ("lib/class/someclass.php");
// clean the output buffer
ob_clean();
// simple test image
header("Content-type: image/gif");
$im = imagecreate (100, 50);
imagegif($im);
imagedestroy($im);
?>
While this may seem trivial a trivial use of the function, it in fact is incredibly useful for
insuring no extra spaces or new lines have already been output while making images in php. As many
of you probably already know, extra lines, spacing and padding that appears prior to image-code will
prevent the image from being created. If the file "lib/somelibrary.php" had so much as an
extra new line after the closing php tag then it would completely prevent the image from working in
the above script.
If you work on an extremely large project with a lot of source and required files, like myself, you
will be well-advised to always clear the output buffer prior to creating an image in php.
----
Server IP: 212.63.193.10
Probable Submitter: 83.227.147.212
----
Manual Page -- http://www.php.net/manual/en/function.ob-clean.php
Edit -- https://master.php.net/note/edit/75694
Del: integrated -- https://master.php.net/note/delete/75694/integrated
Del: useless -- https://master.php.net/note/delete/75694/useless
Del: bad code -- https://master.php.net/note/delete/75694/bad+code
Del: spam -- https://master.php.net/note/delete/75694/spam
Del: non-english -- https://master.php.net/note/delete/75694/non-english
Del: in docs -- https://master.php.net/note/delete/75694/in+docs
Del: other reasons-- https://master.php.net/note/delete/75694
Reject -- https://master.php.net/note/reject/75694
Search -- https://master.php.net/manage/user-notes.php