PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.php > php style for writing static (.html pages
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
php style for writing static (.html pages

Réponse
 
LinkBack Outils de la discussion
Vieux 16/06/2008, 22h40   #1
Jeff
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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
  Réponse avec citation
Vieux 16/06/2008, 23h14   #2
Paul Furman
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: php style for writing static (.html pages

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 more, maybe searching
with 'mode' added s.

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

all google groups messages filtered due to spam
  Réponse avec citation
Vieux 17/06/2008, 00h36   #3
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: php style for writing static (.html pages

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.
jstucklex@attglobal.net
==================

  Réponse avec citation
Vieux 17/06/2008, 01h20   #4
Jeff
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: php style for writing static (.html pages

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
>

  Réponse avec citation
Vieux 17/06/2008, 02h43   #5
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: php style for writing static (.html pages

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.
jstucklex@attglobal.net
==================

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 07h13.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,15782 seconds with 13 queries