Generate HTML from PHP

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I am just wondering if it is possible to save a HTML string from PHPs?
Let me elaborate more on what I mean.

If you do
include 'abc.php'

echo "Hi, I'm a PHP script!";
<?php $a_number = 5?>
<javascript ...
<?php echo $a_number ?>

I am looking for a way to display only HTML and javascript and have
$a_number replaced with 5.

I need something that will display resulting HTML of PHP execution. So
if there are functions or database queries in PHP, the HTML string
will reflect the result of function execution or retrieved result from
database queries. Not the function definition or database query

In other words, process a seperate PHP file and return its HTML output
like the INCLUDE function, but do not output it (instead set it to a
variable value).

Re: Generate HTML from PHP

Mike wrote:

Quoted text here. Click to load it

include 'file.php';

Justin Koivisto -

Re: Generate HTML from PHP

Quoted text here. Click to load it

Just out of pure curiosity, why would you possibly want to do this?


Re: Generate HTML from PHP

Nel wrote:
Quoted text here. Click to load it

In any instance where you want to generate your output and display it

My PSA project ( uses it, my CMS that I
am working on uses it, and any time that I want to create a "cached"
version of dynamic output, I do the same thing:

1. ob start();
2. generate all the HTML necessary
3. $contents=ob_get_clean()
4. open file and write $contents to it.

The ob_* functions are handy when you are generating error messages to
display later in the HTML. The ob_* functions also don't prevent the
header() function from working. Therefore, if you have a condition that
you want to use header and forward the user to another page, you can
still generate all the HTML that would be output if that condition is
not met.

Justin Koivisto -

Site Timeline