ob-start

PHP ob_start vs opcode APC, explain differences and real world usage?

半腔热情 提交于 2019-12-23 08:46:56
问题 Premise: I'm not trying to reinvent the wheel, I'm just trying to understand. Output caching can be implemented easily: //GetFromMyCache returns the page if it finds the file otherwise returns FALSE if( ($page = GetFromMyCache($page_id)) !== FALSE ) { echo $page; //sending out page from cache exit(); } //since we reach this point in code, it means page was not in cache ob_start(); //let's start caching //we process the page getting data from DB //saving processed page in cache and flushing it

ob_start echo's strings out still

左心房为你撑大大i 提交于 2019-12-22 10:27:03
问题 I'd like it if ob_start() didn't let echo's output to their normal destination and just log their contents instead. But it doesn't seem to be doing that. Any ideas? Here's my code: <?php ob_start(); echo 'test'; $out = ob_get_contents(); var_dump($out); test is still echo'd. It's var_dump'd, as well, but I don't want it to be echo'd. Any ideas? Thanks! 回答1: The output buffer is automatically flushed at the end of the script, so it's expected behaviour. You are looking for ob_get_clean(),

How to redirect with header location in php when using ob_start?

﹥>﹥吖頭↗ 提交于 2019-12-20 03:34:10
问题 <?php ob_start(); echo "<body><p>Hello " if ($condition) { header( "Location: http://www.google.com/" ); exit; } echo " World!</p></body>"; ob_end_flush(); ?> When $condition is true I get this: <body>Hello What I want is when $condition will be true then go to Google!!! I don't know what is happening, can you explain or give me a solution!? Thanks. 回答1: Just add ob_end_clean(); before the header call. 回答2: Everything should work, just put an ; after echo " <body><p>Hello " and you will be

Email function using templates. Includes via ob_start and global vars

∥☆過路亽.° 提交于 2019-12-19 10:03:12
问题 I have a simple Email() class. It's used to send out emails from my website. <? Email::send($to, $subj, $msg, $options); ?> I also have a bunch of email templates written in plain HTML pierced with a few PHP variables. E.g. /inc/email/templates/account_created.php : <p>Dear <?=$name?>,</p> <p>Thank you for creating an account at <?=$SITE_NAME?>. To login use the link below:</p> <p><a href="https://<?=$SITE_URL?>/account" target="_blank"><?=$SITE_NAME?>/account</a></p> In order to have the PHP

PHP Should I use ob_clean after ob_start

自古美人都是妖i 提交于 2019-12-14 01:30:08
问题 I made a simple login-system in php and mysql, but I keep getting errors saying that headers already been sent, and using ob_start fixes this problem, but im not sure if I should then use ob_clean at the footer afterward? Also, the error comes when I have logged in to the account page, saying header already been sent in previuos page - > header("Location: account.php"); But I have to redirect the user when they login. My login page looks like this require_once('models/init.php'); // db

CodeIgniter, How to modify buffered output before sending

纵然是瞬间 提交于 2019-12-12 02:06:14
问题 I would like to alter the output throughout my Codeigniter-based website. Quite simply I would like to do $output = str_replace( array('ā','ē','ī','ō','ū','Ā','Ē','Ī','Ō','Ū'), array('a','e','i','o','u','A','E','I','O','U'), $output ) In the event that the user prefers so. By reading questions and answers here, I found a link that could help.. https://www.codeigniter.com/user_guide//general/controllers.html#processing-output ..but it only works controller by controller and that would be

Output Buffer shows “1”

回眸只為那壹抹淺笑 提交于 2019-12-11 05:06:05
问题 I have two functions: core_function($atts) { (attributes) (core functions, a few loops, echoes, a lot of direct input) } And that's how I display my function using output buffering (yes, I have to use it!). display_function($atts) { (attributes) $output = ob_start(); $output .= core_function($atts); $output .= ob_get_clean(); return $output; } Everything is perfectly fine, but return $output shows not only core functions but also "1" before them. I have no idea where this "1" comes from. When

why do I need to end my ob_start()?

二次信任 提交于 2019-12-10 02:28:44
问题 The php documentation suggests that I should end each ob_start() with an ob_end_flush(). I am using one on each page of a site, just to allow me to use firephp log methods anywhere in the app. the app works fine, but I wonder if there is anything I don't know that might be detrimental. 回答1: I think the reason for this suggestion is, that PHP flushes your output buffer implicitly when not using one of the ob_end_* functions. While not an error, this can cause problems when not expecting it.

Cannot use output buffering in output buffering display handlers

冷暖自知 提交于 2019-12-08 15:58:35
问题 I've reinstalled Apache, and switched from PHP 5.3 to 5.6. Everything works, except I get this error, when calling ob_start() : Cannot use output buffering in output buffering display handlers I tried to enable output buffering in PHP, but I still get this error: output_buffering = 4096 回答1: Probably you are using a buffering function in output buffering callback which isn't possible as mentioned in php ob_start output_callback documentation. If not it should be the output-handler you used,

ob_start echo's strings out still

て烟熏妆下的殇ゞ 提交于 2019-12-05 20:53:24
I'd like it if ob_start() didn't let echo's output to their normal destination and just log their contents instead. But it doesn't seem to be doing that. Any ideas? Here's my code: <?php ob_start(); echo 'test'; $out = ob_get_contents(); var_dump($out); test is still echo'd. It's var_dump'd, as well, but I don't want it to be echo'd. Any ideas? Thanks! The output buffer is automatically flushed at the end of the script, so it's expected behaviour. You are looking for ob_get_clean() , which returns the current buffer before clearing it: $out = ob_get_clean(); 来源: https://stackoverflow.com