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
==================