Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nextend/eb062de0ac2f077b7156170fb10f4084 to your computer and use it in GitHub Desktop.
Save nextend/eb062de0ac2f077b7156170fb10f4084 to your computer and use it in GitHub Desktop.
Before you want to send files or structured data over and AJAX call from PHP you might need to clean all output buffers (ob_start(...)) to be able to trash the junk in the buffers. It especially can happen in CMS like Joomla, WordPress etc.. when other plugin does strange things.
<?php
function ob_end_clean_all() {
$handlers = ob_list_handlers();
while (count($handlers) > 0 && $handlers[count($handlers) - 1] != 'ob_gzhandler' && $handlers[count($handlers) - 1] != 'zlib output compression') {
ob_end_clean();
$handlers = ob_list_handlers();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment