473,396 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Generate HTML from PHP

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).
Jul 17 '05 #1
3 3009
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 - sp**@koivi.com
http://www.koivi.com
Jul 17 '05 #2
Nel
"Mike" <mi****@gmail.com> wrote in message
news:8e**************************@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.
Jul 17 '05 #3
Nel wrote:
"Mike" <mi****@gmail.com> wrote in message
news:8e**************************@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 - sp**@koivi.com
http://www.koivi.com
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Fred | last post by:
Hi, I'm sure there are a bunch of them, but googling just returned full-fledged CMS that require a DBMS and generate dynamic pages. I'd just like a script that would 1. look in a directory...
1
by: Tim:. | last post by:
Hi Can someone tell me how I generate a new XML file that I can then use with an XSLT file. I am trying to use an XML file generated from Microsoft Project or even better generate an XML file from...
4
by: Dehaibe François | last post by:
Hi, I'm making a program which uses a scanner which is enable to can multiple pages. I want to save all the scanned images into a PDF FILE. Does exist an API which can generate PDF FILE in...
2
by: Nick | last post by:
Hi all, I'm about to embark on a new project and can't decide quite how to do it. In summary, I have a database whose data I want to use to create html pages for a website. The website will just...
7
by: Rathtap | last post by:
I want to write a C# application (lets call it Generator) that will receive an argument(patient account number) and dynamically generate a series of linked HTML files (claim information, payments,...
1
by: A Traveler | last post by:
Hello, i am having this problem. The exact error message is: "Unable to generate code for a value of type 'System.Web.UI.Page'. This error occurred while trying to generate the property value for...
0
by: ward | last post by:
Greetings. Ok, I admit it, I bit off a bit more than I can chew. I need to complete this "Generate Report" page for my employer and I'm a little over my head. I could use some additional...
6
by: ash | last post by:
i have a web page using frameset split into few pages. And I want to generate one page of HTML code and send it through email. My question is have to generate a HTML page using asp? Thx very much.
1
by: Daniel Hilgarth | last post by:
Hello, I am currently trying to use XSLT for the creation of multiple HTML-files from a single XML-File. This HTML-files need to have links to each other. The following information might be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.