This is a discussion on Generate HTML from PHP within the PHP Language forums, part of the PHP Programming Forums category; I am just wondering if it is possible to save a HTML string from PHPs? Let me elaborate more on ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 <?php include 'abc.php' ?> //abc.php <html> <head> <title>Example</title> </head> <body> <?php echo "Hi, I'm a PHP script!"; ?> </body> </html> <?php $a_number = 5?> <javascript ... <?php echo $a_number ?> /javascript> 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 strings. 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). |
|
|||
|
Mike wrote:
> 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 > <?php > include 'abc.php' > ?> > > //abc.php > <html> > <head> > <title>Example</title> > </head> > <body> > <?php > echo "Hi, I'm a PHP script!"; > ?> > </body> > </html> > <?php $a_number = 5?> > <javascript ... > <?php echo $a_number ?> > /javascript> > > 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 > strings. > > 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). ob_start(); include 'file.php'; $var=ob_get_clean(); -- Justin Koivisto - spam@koivi.com http://www.koivi.com |
|
|||
|
"Mike" <michma@gmail.com> wrote in message
news:8e9b7c06.0409211234.5170941e@posting.google.c om... > 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 > <?php > include 'abc.php' > ?> > > //abc.php > <html> > <head> > <title>Example</title> > </head> > <body> > <?php > echo "Hi, I'm a PHP script!"; > ?> > </body> > </html> > <?php $a_number = 5?> > <javascript ... > <?php echo $a_number ?> > /javascript> > > 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 > strings. > > 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). Just out of pure curiosity, why would you possibly want to do this? Nel. |
|
|||
|
Nel wrote:
> "Mike" <michma@gmail.com> wrote in message > news:8e9b7c06.0409211234.5170941e@posting.google.c om... > >>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 >><?php >>include 'abc.php' >>?> >> >>//abc.php >><html> >><head> >><title>Example</title> >></head> >><body> >><?php >>echo "Hi, I'm a PHP script!"; >>?> >></body> >></html> >><?php $a_number = 5?> >><javascript ... >><?php echo $a_number ?> >>/javascript> >> >>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 >>strings. >> >>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). > > > Just out of pure curiosity, why would you possibly want to do this? In any instance where you want to generate your output and display it later... My PSA project (sf.net/projects/phpsecurityadm) 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 - spam@koivi.com http://www.koivi.com |