Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

output buffer

Posted on 2008-11-05
4
Medium Priority
?
308 Views
Last Modified: 2012-05-05
Hi,
I try to buffer a page. But it send output before my "echo $content" command. How can i disable this?
<?php
ob_start()
?>
<div>test</div>
<?php
$content=ob_get_flush();
echo $content; //I want to send output just this command....
?>

Open in new window

0
Comment
Question by:erenpasa
  • 2
4 Comments
 
LVL 11

Expert Comment

by:jausions
ID: 22887622
Is  that the only files that's loaded? Look for blank lines in other files if that's not the case.

Finally, check for UTF BOM (some hiding characters at the very beginning of a file that identifies it a UTF-encoded). You may want to look for the UTF-encoding related settings in your text editor. PHP doesn't handle these bits very well, and they may be the ones causing problem.
0
 

Author Comment

by:erenpasa
ID: 22888802
i've looked my file but it's seem normal.can you upload a small file for me?
is my code run at your system?
0
 
LVL 11

Accepted Solution

by:
jausions earned 750 total points
ID: 22888926
If it's a UTF BOM issue, yes, your file will look normal. As stated, the BOM is hidden in common text editor, so it looks like there is nothing at the first line. So you really need to look at your editor's settings to see if UTF BOM is enabled or not. If it is, you want to turn it off, and save your file making sure it doesn't use UTF BOM marking.

That's one of the possible problem.

Another reason might be that you use ob_get_flush() which returns the buffer's content AND output it to the client. Look at ob_get_clean() (PHP5) or ob_get_contents() / ob_end_clean() (PHP4) otherwise.
0
 
LVL 11

Assisted Solution

by:NoiS
NoiS earned 750 total points
ID: 22889403
Whe you call ob_get_flush(); The buffer is outputted;
Instead use ob_get_clean(); if you need to cleand the buffer after get the content;
or ob_get_contents(); if you need the buffer intact;
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question