PHP.mk документација

ob_clean

Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.

function.ob-clean.php PHP.net прокси Преводот се освежува
Оригинал на PHP.net
Патека function.ob-clean.php Локална патека за оваа страница.
Извор php.net/manual/en Оригиналниот HTML се реупотребува и локално се стилизира.
Режим Прокси + превод во позадина Кодовите, табелите и белешките остануваат читливи во истиот тек.
ob_clean

Референца за `function.ob-clean.php` со подобрена типографија и навигација.

function.ob-clean.php

ob_clean

(PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8)

ob_cleanИсчисти (избриши) ја содржината на активниот излезен бафер

= NULL

ob_clean(): bool

Оваа функција го повикува ракувачот со излез (со PHP_OUTPUT_HANDLER_CLEAN знаме), го отфрла неговата вратена вредност и ја чисти (брише) содржината на активниот излезен бафер.

знаме), испраќа (испраќа) неговата вратена вредност и ги отфрла содржините на активниот излезен бафер. ob_end_clean() or ob_get_clean() does.

ob_clean() ќе откаже без активен бафер за излез започнат со PHP_OUTPUT_HANDLER_CLEANABLE flag.

Параметри

Оваа функција нема параметри.

Вратени вредности

Патеката до PHP скриптата што треба да се провери. true на успех или false при неуспех.

Errors/Exceptions

Ако функцијата откаже, генерира E_NOTICE.

Види Исто така

  • ob_start() - Вклучи баферирање на излезот
  • ob_get_contents() - Врати ги содржините на излезниот бафер
  • ob_end_clean() Исчисти (избриши) ја содржината на активниот излезен бафер и исклучи го
  • ob_get_clean() - Земи ја содржината од активниот бафер за излез и исклучи го
  • ob_flush() - Испрати (испрати) вратена вредност од активниот ракувач за излез

Белешки од корисници 4 белешки

meustrus
12 години пред
@cornel: It's easy enough to say "Don't do that" when you think you've got the person right in front of you. But one doesn't always have the original coder, or even one of a dozen of the original coders. Are you really suggesting that it would be wrong to use this function as a band-aid when the alternative may be looking through hundreds of source files you didn't write for errors you didn't introduce?

To your point, though, it is (or should be) a commonly accepted best practice to not put closing PHP tags at the end of files. When, however, enforcing that would take a time machine, it's appropriate to use ob_clean() as a band-aid to make dynamically generated images work as expected.
lev на taintedthoughts точка com
пред 18 години
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.
cornel на scoalaweb точка com
пред 13 години
Don't use ob_clean() to clear white-space or other unwanted content "accidentally" generated by included files.
Included files should not generate unwanted content in the first place.
If they do, You are doing something wrong, like inserting white-space after "?>" (there should not be a "?>" at the end of PHP files: http://php.net/manual/en/language.basic-syntax.phptags.php ).
alexander на mralexander точка ca
пред 11 години
In case there is nothing output yet to the buffer and then implementing the ob_clean() a (soft) error notice would be generated such as the following:

Notice: ob_clean() [ref.outcontrol]: failed to delete buffer. No buffer to delete. in [file-path]

you could do a simple check with "ob_get_contents()" to make sure that there is anything in the buffer.
На оваа страница

Автоматски outline од активната документација.

Насловите ќе се појават тука по вчитување.

Попрегледно читање

Примерите, changelog табелите и user notes се визуелно издвоени за да не се губат во долгата содржина.

Брз совет Користи го outline-от Скокни директно на главните секции од активната страница.
Извор Оригиналниот линк останува достапен Кога ти треба целосен upstream context, отвори го PHP.net во нов tab.