473,766 Members | 2,035 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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>Exampl e</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 3045
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>Exampl e</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_cle an();

--
Justin Koivisto - sp**@koivi.com
http://www.koivi.com
Jul 17 '05 #2
Nel
"Mike" <mi****@gmail.c om> wrote in message
news:8e******** *************** ***@posting.goo gle.com...
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>Exampl e</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.c om> wrote in message
news:8e******** *************** ***@posting.goo gle.com...
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>Exampl e</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_ge t_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
2313
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 for articles in raw HTML, 2. generate a cooked output for each page (ie. add header and footer, CSS link in HEAD, etc.), 3. regenerate the homepage with "Last modified" bit following each
1
2343
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 the project file (MPP File) itself. Which I can then use with an XSLT file I am new to XML and want to create a project viewer using XML, ASP and XHTML. I have an idea of how this should work but would really appritiate any help someone can...
4
43227
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 .NET ? Best Regards,
2
2291
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 be a series of static html pages. I will keep all the data locally and would generate the required pages and upload them whenever I needed to. I do not want to have the database anywhere but on my lcoal machine. My questions are:
7
25366
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, denials etc) by querying a database based on the argument. This Generator can be called from an aspx web page, a Cold Fusion page as well as from a windows application. 1. Does this C# app have to be a console application to receive arguments?...
1
2325
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 Page." After a lot of googling, all i can find that this applies to is when trying to use enum-type datatypes as bit-vector flags, or when use designers to make an expandable property in the property tool-window. However, NEITHer of these...
0
2259
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 assistance. I say additional because I've already had help which is greatly appreciated. I do try to take the time and understand the provided script in hopes on not having to trouble others on those. But here it goes...
6
5241
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
3655
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 important: There are some special nodes that will start a new HTML-page ("page-nodes"). Those nodes can be nested. Those nodes have an attribute "name" which is not necessarily unique. There are another special nodes that will create a link in one...
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9404
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10008
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9837
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8833
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6651
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5279
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3929
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.