tmallen Posted February 21, 2010 Share Posted February 21, 2010 The cache file is created, but it's empty. I can pass in a debug string which is written successfully. <?php function page($name, $params = array(), $cache = false) { if(is_array($params)) { extract($params); } else { $title = $params; } function put_page($name) { ob_start(); include sprintf('pages/%s.php', $name); $content = ob_get_clean(); include 'pages/page.php'; return ob_get_flush(); } if($cache) { $cache_file = sprintf('cache/page/%s.html', $name); if(file_exists($cache_file)) { echo file_get_contents($cache_file); unlink($cache_file); } else { if(!is_dir('cache/page')) { mkdir('cache/page'); } $cached = fopen($cache_file, 'w'); fwrite($cached, put_page($name)); fclose($cached); } } else { put_page($name); } } Link to comment https://forums.phpfreaks.com/topic/192791-why-does-ob_get_flush-return-an-empty-string/ Share on other sites More sharing options...
teamatomic Posted February 21, 2010 Share Posted February 21, 2010 ob_start(); include sprintf('pages/%s.php', $name); $content = ob_get_clean(); include 'pages/page.php'; return ob_get_flush(); You must decide what you want to do. You use ob_get_flush to put the buffer into $content then expect return ob_get_flush to give you something from an empty buffer. Either return from the function or the contents of the buffer into $contents, but not both HTH Teamatomic Link to comment https://forums.phpfreaks.com/topic/192791-why-does-ob_get_flush-return-an-empty-string/#findComment-1015552 Share on other sites More sharing options...
tmallen Posted February 21, 2010 Author Share Posted February 21, 2010 ob_get_flush returns the contents of the output buffer. After the clean, shouldn't the include add to the buffer, being the contents of that returned string? Link to comment https://forums.phpfreaks.com/topic/192791-why-does-ob_get_flush-return-an-empty-string/#findComment-1015553 Share on other sites More sharing options...
teamatomic Posted February 21, 2010 Share Posted February 21, 2010 flush is the term. ob_get_flush flushes the buffer contents to a var, ob_put_contents flushes the buffer to page output. How can the include add to the buffer after it has already added and been flushed? if that is what you want you need to first start a new buffer. ob_start(); include sprintf('pages/%s.php', $name); $content = ob_get_clean(); ob_start(); include 'pages/page.php'; return ob_get_flush(); HTH Teamatomic Link to comment https://forums.phpfreaks.com/topic/192791-why-does-ob_get_flush-return-an-empty-string/#findComment-1015557 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.