Page 1 of 1

Problem With ob_get_clean

Posted: Sat Jul 28, 2007 5:53 am
by IAD
Hey,

I'm trying to print an output, but it comes out before the HTML code, so i've placed ob_start and ob_get_clean functions but now it's not printing anything.

Code:

Code: Select all

<?php

	
	class main_menuErr extends Exception 
	{
		function __construct()
		{
			
		}
	}
	class mainErr extends Exception 
	{
		function __construct()
		{
			Exception::__construct();
		}
	}
	class main_menu
	{
		private $tpl = 'templates/desktop/tpl/main_menu.tpl';
		

		function load()
		{
			global $DB;
		
			ob_start();
		
				$DB -> query("select * from `main_menu`");
					while($DB -> fetch())
					{
						
						if(!($handle = @fopen($this ->tpl,"r")))
							throw new mainErr();
							
							$file = fread($handle, filesize($this -> tpl));
							
								$file = str_replace('<%title%>',$DB['title'],$file);
								$file = str_replace('<%image%>',$DB['image'],$file);
								$file = str_replace('<%width%>',$DB['width'],$file);
								$file = str_replace('<%height%>',$DB['height'],$file);
								$file = str_replace('<%left%>',$DB['left'],$file);
								$file = str_replace('<%desc%>',$DB['description'],$file);
								$file = str_replace('<%module%>','modules/'.$DB['module'],$file);
								$file = str_replace('<%top%>',$DB['top'],$file);
								$file = str_replace('<%max%>',$DB['max'],$file);
								
						print $file;
						
						fclose($handle);
						
						
					}
					
			
		
			return(ob_get_clean());
			
		}

	}

	try 
	{
		
		$main_menu = new main_menu;
		$main_menu -> load();
		
	}
	
	catch(main_menuErr $err)
	{
		print $err -> getMessage();
	}
	
	
	
?>

Thanks in advance, Tal.

Posted: Sat Jul 28, 2007 6:40 am
by superdezign
Then stop printing the value, and just return it. The actual output shouldn't be handled during the function.

Posted: Sat Jul 28, 2007 9:07 am
by IAD
well i've tryed it, but still no affect, it's printing the output before the html output.

Code: Select all

<?php

	
	class main_menuErr extends Exception 
	{
		function __construct()
		{
			
		}
	}
	class mainErr extends Exception 
	{
		function __construct()
		{
			Exception::__construct();
		}


	}
	class main_menu
	{
		private $tpl = 'templates/desktop/tpl/main_menu.tpl';
		

		function __construct()
		{
			global $DB;
		
			
		
				$DB -> query("select * from `main_menu`");
					while($DB -> fetch())
					{
						
						if(!($handle = @fopen($this ->tpl,"r")))
							throw new mainErr();
							
							$file = fread($handle, filesize($this -> tpl));
							
								$file = str_replace('<%title%>',$DB['title'],$file);
								$file = str_replace('<%image%>',$DB['image'],$file);
								$file = str_replace('<%width%>',$DB['width'],$file);
								$file = str_replace('<%height%>',$DB['height'],$file);
								$file = str_replace('<%left%>',$DB['left'],$file);
								$file = str_replace('<%desc%>',$DB['description'],$file);
								$file = str_replace('<%module%>','modules/'.$DB['module'],$file);
								$file = str_replace('<%top%>',$DB['top'],$file);
								$file = str_replace('<%max%>',$DB['max'],$file);
								
						$this -> file = $file;
						
						fclose($handle);
						
						
					}
					
			
		
			return $this -> file;
			
			
		}

	}

	try 
	{
		
		$main_menu = new main_menu;
		
			print $main_menu -> file;
			
		
	}
	
	catch(main_menuErr $err)
	{
		print $err -> getMessage();
	}
	
	
	
?>
the result on my page is:

Code: Select all

<div class="module" onclick="pmWin('Online Statistics Of Your Hole Site','modules/getStatistics.php',500,250,200,100,1);">
	<img src="templates/desktop/imgs/c.png" style="cursor:pointer;" onmouseover="imgOpacity(this,0);" onmouseout="imgOpacity(this,1);" alt="{$details -> WinTitle}" />
	<br />
	<div class="text">Online Statistics</div>
</div>

<html> <!-- start of the page, module should be after the <body> not before the <html> -->