You are here: Re: Dynamically generated HTML « All PHP « IT news, forums, messages
Re: Dynamically generated HTML

Posted by William Wilcox on 10/22/05 09:23

In article <4ied-0A4BA2.15375221102005@comcast.dca.giganews.com>,
William Wilcox <4ied@comcast.net> wrote:

> What I'm trying to do: Have one main script, which depending on the
> variables passed to it, generates different content in HTML. I want 3
> functions, one to generate the HTML header, one to generate the body and
> one to generate the footer. What's returned from all three functions
> should be put into one document and passed back to the browser.

I think I may be stumbling in the right direction, but clarification
from someone more familiar with what I'm trying to do would be
appreciated.

Since my original post I've discovered ob_start() and ob_flush(). This
promises to do exactly what I want. My main script starts a buffer to
hold everything till all the parts are done executing, and then flush
the whole bit back to the browser.

I still have a problem in that the code generated from my function isn't
being passed back to the main program, and therefore it's not in the
buffer to be flushed.

I put the function into it's own file and call it from the main program
like this:

//START
ob_start();
require('./site/header.php');
ob_flush();
//STOP

Nothing is passed to the browser. If I execute the function directly
from the browser it sends the code I expect. This isn't the whole code,
but what I'm working with at the moment to find the solution to my
problem.

It seems I still don't understand how I can get the function to pass the
resulting html header text back to the main program.

If I put the function into a class as a method, and then create an
object to access the method from the body of my main program
(remembering to include the class file), would that then make the output
of the method available to the main program?

I've tried this as well using the following code in the body of my main
program:

// START
require "./site/test.php"; //Where the header class exists
require "HTML/Template/IT.php";
require "DB.php";
require "db.inc";

// Try to buffer the output.
ob_start();

// Make an instance of the header class
$head = new Header();

// Execute the method which should create the header
$head->displayHeader();

// Now flush the buffer contents
ob_flush();
//STOP

I have the same problem here. The page returned to the browser is
completely blank with no HTML code at all. I'm still missing some bit
of php wisedom...well I'm missing a lot of wisedom actually, but that's
another topic. ;-)

Just for kicks and grins, here's what I've been reading about output
buffering.
http://www.devshed.com/c/a/PHP/Output-Buffering-With-PHP/1/
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=1076&
lngWId=8
http://us2.php.net/manual/en/function.ob-start.php

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация