473,327 Members | 1,952 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,327 software developers and data experts.

php style for writing static (.html pages

I've been working on porting some perl CMS code to PHP.

What I would do in perl is search through a template for instruction
and replace those instructions with specific bits for that particular
page and page path.

With PHP it's easy to embed instruction in the html and output thhat
as a .php page. How do I write a .html as a file?

I can think of some awkward ways to do this.

1) You could take a a server page and read and rewrite that as a file.

2) Perhaps you could take the whole "template":

$template=<<<TEMPLATE
<html>
<body....
<?php

somePHPFunctionality();

?>
....
</html>

TEMPLATE;
and eval that (and write the return to a file), but I'm reminded that
if eval is the answer then you are probably asking the wrong question.

There must a be an easy PHP way to do this, what is it? I'm looking
through Smarty at the moment, I don't think this is it...

Jeff
Jun 27 '08 #1
4 1892
Jeff wrote:
<?php

somePHPFunctionality();

?>
...
</html>

TEMPLATE;

and eval that (and write the return to a file), but I'm reminded that
if eval is the answer then you are probably asking the wrong question.

There must a be an easy PHP way to do this, what is it? I'm looking
through Smarty at the moment, I don't think this is it...
I think there's a mode you can run to generate files rather than feed
the results to the server... wish I could help more, maybe searching
with 'mode' added helps.

--
Paul Furman
www.edgehill.net
www.baynatives.com

all google groups messages filtered due to spam
Jun 27 '08 #2
Jeff wrote:
I've been working on porting some perl CMS code to PHP.

What I would do in perl is search through a template for instruction
and replace those instructions with specific bits for that particular
page and page path.

With PHP it's easy to embed instruction in the html and output thhat as
a .php page. How do I write a .html as a file?

I can think of some awkward ways to do this.

1) You could take a a server page and read and rewrite that as a file.

2) Perhaps you could take the whole "template":

$template=<<<TEMPLATE
<html>
<body....
<?php

somePHPFunctionality();

?>
...
</html>

TEMPLATE;
and eval that (and write the return to a file), but I'm reminded that
if eval is the answer then you are probably asking the wrong question.

There must a be an easy PHP way to do this, what is it? I'm looking
through Smarty at the moment, I don't think this is it...

Jeff
Jeff,

Well, you have a problem in that the server won't parse php in .html
files, unless you change the server configuration (which is a bad idea).
So any PHP code in a .html page will just be output on the page.

You can use PHP code to generate a .HTML file; just use the PHP string
functions such as str_replace() to replace template placeholders with
the appropriate information (or you can get more complicated).

It's not a good idea to use eval() - if someone hacks your system, you
could be evaluating some unknown code - which could do a lot of harm.

Just wondering - why do you want to save it as a .html file? What's
wrong with just using a .php file and executing the code when someone
requests the page?

Or maybe I'm not clear on exactly what you're trying to do.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Jun 27 '08 #3
Jerry Stuckle wrote:
Jeff wrote:
Hi Jerry, nice to hear from you. Looks like a nice bunch here in the php
group. They've been kind while I'm getting up to speed.
> I've been working on porting some perl CMS code to PHP.

What I would do in perl is search through a template for instruction
and replace those instructions with specific bits for that particular
page and page path.

With PHP it's easy to embed instruction in the html and output thhat
as a .php page. How do I write a .html as a file?

I can think of some awkward ways to do this.

1) You could take a a server page and read and rewrite that as a file.

2) Perhaps you could take the whole "template":

$template=<<<TEMPLATE
<html>
<body....
<?php

somePHPFunctionality();

?>
...
</html>

TEMPLATE;
and eval that (and write the return to a file), but I'm reminded that
if eval is the answer then you are probably asking the wrong question.

There must a be an easy PHP way to do this, what is it? I'm looking
through Smarty at the moment, I don't think this is it...

Jeff

Jeff,

Well, you have a problem in that the server won't parse php in .html
files, unless you change the server configuration (which is a bad idea).
So any PHP code in a .html page will just be output on the page.

You can use PHP code to generate a .HTML file; just use the PHP string
functions such as str_replace() to replace template placeholders with
the appropriate information (or you can get more complicated).
In perl I'm using a regex with an "e" execute flag. It looks to me that
in PHP that would be: preg_replace_callback. For example here's a bit
of perl I use to parse a template for xsl tags and call the appropriate
functions.

foreach($config_file=~s/<xsl(.*?)>/parseTag($1,$self->{page})/eg){
}

I thought there might be a php way.
>
It's not a good idea to use eval() - if someone hacks your system, you
could be evaluating some unknown code - which could do a lot of harm.
Well if someone hacks your system you've got problems anyways!
>
Just wondering - why do you want to save it as a .html file? What's
wrong with just using a .php file and executing the code when someone
requests the page?
I'd rather serve static pages when needed, why should the server
remake the page each time it's called rather than just when it's
modified. Also, I'd rather each page had a separate name and page path
(yes I realize I can fake this with apache rewrite splitting query strings).

I don't have a clear handle on PHP yet. I'd rather work with just a
template(s), that way if you want to change the base html of the site
you just change the templates. It seems to me that with php pages with
embedded scripting that you would need to remake each page.

Database driven pages are a different matter, but having a template
drive this also makes sense to me as far as having the same look.
>
Or maybe I'm not clear on exactly what you're trying to do.
Probably. I'm a little off the beaten path at times and not as
coherent as I'd like.

Feel free to correct me...

Jeff
>
Jun 27 '08 #4
Jeff wrote:
Jerry Stuckle wrote:
>Jeff wrote:

Hi Jerry, nice to hear from you. Looks like a nice bunch here in the php
group. They've been kind while I'm getting up to speed.
>> I've been working on porting some perl CMS code to PHP.

What I would do in perl is search through a template for instruction
and replace those instructions with specific bits for that particular
page and page path.

With PHP it's easy to embed instruction in the html and output thhat
as a .php page. How do I write a .html as a file?

I can think of some awkward ways to do this.

1) You could take a a server page and read and rewrite that as a file.

2) Perhaps you could take the whole "template":

$template=<<<TEMPLATE
<html>
<body....
<?php

somePHPFunctionality();

?>
...
</html>

TEMPLATE;
and eval that (and write the return to a file), but I'm reminded
that if eval is the answer then you are probably asking the wrong
question.

There must a be an easy PHP way to do this, what is it? I'm looking
through Smarty at the moment, I don't think this is it...

Jeff

Jeff,

Well, you have a problem in that the server won't parse php in .html
files, unless you change the server configuration (which is a bad
idea). So any PHP code in a .html page will just be output on the page.

You can use PHP code to generate a .HTML file; just use the PHP string
functions such as str_replace() to replace template placeholders with
the appropriate information (or you can get more complicated).

In perl I'm using a regex with an "e" execute flag. It looks to me that
in PHP that would be: preg_replace_callback. For example here's a bit
of perl I use to parse a template for xsl tags and call the appropriate
functions.

foreach($config_file=~s/<xsl(.*?)>/parseTag($1,$self->{page})/eg){
}

I thought there might be a php way.
Yes, you can with a callback. But I'm about as far from a regex expert
as you are a PHP expert :-)
>>
It's not a good idea to use eval() - if someone hacks your system, you
could be evaluating some unknown code - which could do a lot of harm.

Well if someone hacks your system you've got problems anyways!
Yes, but eval() is especially dangerous. What happens if for instance,
a hacker places the following in a text area?

<?php exec("rm -R ."); ?>

Now you insert this into a page and eval() the page.

This is a very simple, but possible example. There are a lot more ways
to hack stuff into a page if you're not *very careful*. It's much
better to not use eval(). It really isn't needed if you design properly.
>>
Just wondering - why do you want to save it as a .html file? What's
wrong with just using a .php file and executing the code when someone
requests the page?

I'd rather serve static pages when needed, why should the server remake
the page each time it's called rather than just when it's modified.
Also, I'd rather each page had a separate name and page path (yes I
realize I can fake this with apache rewrite splitting query strings).
Because the data is current. And there isn't that much overhead. Sure,
if you're getting 10K hits/second, you would want to serve static pages.
But very few sites get close to that.
I don't have a clear handle on PHP yet. I'd rather work with just a
template(s), that way if you want to change the base html of the site
you just change the templates. It seems to me that with php pages with
embedded scripting that you would need to remake each page.
Sure. That's the way it works. And it works fine.
Database driven pages are a different matter, but having a template
drive this also makes sense to me as far as having the same look.
>>
Or maybe I'm not clear on exactly what you're trying to do.

Probably. I'm a little off the beaten path at times and not as
coherent as I'd like.

Feel free to correct me...

Jeff
>>
No, you're just prematurely optimizing your code. Create the pages
dynamically. Then if you have a problem, work on optimizing that
problem. Unless your server is way overloaded (in which case you
shouldn't be using it anyway) or your code is very inefficient, you will
still have great response time.

You can do it your way - but you're just needlessly complicating matters.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Jun 27 '08 #5

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

Similar topics

55
by: James A. Donald | last post by:
In a book, a footnote is presented at the bottom of the page, in a slightly smaller type. converting a book to html, pages are bottomless, so we can put the footnote in a separate link, or...
6
by: Ken Varn | last post by:
I want to add my own custom <STYLE> section in the <HEAD> section of my ASP.NET page within a custom control. Can someone tell me how I can have my custom control add tags to the <HEAD> section of...
2
by: Kenneth P | last post by:
Hi, I'm developing asp.net (vb) apps in VS.NET 2003, and I'd like to know how you can write style sheet code in a sub in an .aspx page that when it's rendered as html/text/css code in the .aspx...
5
by: MarkW | last post by:
I hope this is the correct place to post this: I am developing a web site for a e-commerce business I will be running. The site I'm setting up will be 50% store, 50% content. I'm not sure which...
8
by: JT | last post by:
Hi, I have done a fair amount of style editing inline in ASP. I'm now using VS 2005 with a standard web project (not Web Application Project). This is my first foray into CSS in a style sheet...
5
by: pittendrigh | last post by:
There must be millions of dynamically generated html pages out there now, built by on-the-fly php code (and jsp, perl cgi, asp, etc). Programatic page generation is transparently useful. But...
5
by: =?Utf-8?B?SmVycnkgQw==?= | last post by:
I have a machine running IIS 6.0. I just replaced the web.config and several aspx pages in the application and now the style sheets are not working. the images from the themes work but not the css...
2
by: Steve Swift | last post by:
I have a pair of webservers (actually virtual hosts in the same apache). They are mostly clones, but one is used to develop changes, so is the test system. Most of the pages are generated by CGI...
10
by: Terrence Brannon | last post by:
Hello, The most common way of dynamically producing HTML is via template engines like genshi, cheetah, makotemplates, etc. These engines are 'inline' --- they intersperse programming...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.