merlin
Public Area Guest
Posts: 19
|
Post by merlin on Aug 9, 2004 19:56:03 GMT
In my CGI perl code, something I do on my site a lot is, load a template .html file and then insert strings into set variables or replacement codes... eg.
#!/usr/bin/perl
$basedir = "http://www.icemark.com/winlom99/screenshots";
$input = $ENV{'QUERY_STRING'};
$image = "$basedir/Image" . "$input" . ".jpg";
chdir "../winlom99/";
# open template file open ( FILE, "screenshots.htm" ); @buffer = <FILE>; close ( FILE );
# output template file print "Content-type: text/html\n\n"; foreach $line ( @buffer ) { # change inline html variables $line=~s/__image__/$image/gs; print $line; }
I then call this with www.icemark.com/cgi-bin/winlompic.cgi?1What's the easiest way of doing this in PHP?
|
|
Perun
Public Area Guest
Issa (Vis) [1:76:24]
Posts: 2,506
|
Post by Perun on Aug 9, 2004 22:08:03 GMT
In my CGI perl code, something I do on my site a lot is, load a template .html file and then insert strings into set variables or replacement codes... eg.
#!/usr/bin/perl
$basedir = "http://www.icemark.com/winlom99/screenshots";
$input = $ENV{'QUERY_STRING'};
$image = "$basedir/Image" . "$input" . ".jpg";
chdir "../winlom99/";
# open template file open ( FILE, "screenshots.htm" ); @buffer = <FILE>; close ( FILE );
# output template file print "Content-type: text/html\n\n"; foreach $line ( @buffer ) { # change inline html variables $line=~s/__image__/$image/gs; print $line; }
I then call this with www.icemark.com/cgi-bin/winlompic.cgi?1What's the easiest way of doing this in PHP? Why not ASP?
|
|
merlin
Public Area Guest
Posts: 19
|
Post by merlin on Aug 9, 2004 22:17:16 GMT
Becasue Icemark doesn't have ASP. I've been doing everything in perl up to now, but I figure I'll change over to PHP when I start adding database features into the site. I'm considering a major revamp soon...
|
|
Perun
Public Area Guest
Issa (Vis) [1:76:24]
Posts: 2,506
|
Post by Perun on Aug 9, 2004 22:36:27 GMT
Becasue Icemark doesn't have ASP. I've been doing everything in perl up to now, but I figure I'll change over to PHP when I start adding database features into the site. I'm considering a major revamp soon... If I recall correctly, you can use fopen, fgets, fclose to load contents of an URL into variable. Then use many string manipulating routines to extract and fill variables with data. Or if you're lazy as title suggests ;D, use a template system like smarty (smarty.php.net).
|
|
|
Post by sparrowhawk on Aug 10, 2004 7:42:44 GMT
Chris, Not certain how that's done in PHP, but as I've said elsewhere, if you post a question at the following forum, you'll have an answer within 30 minutes (usually): forums.devnetwork.net/
|
|
merlin
Public Area Guest
Posts: 19
|
Post by merlin on Aug 10, 2004 10:12:18 GMT
Chris, Not certain how that's done in PHP, but as I've said elsewhere, if you post a question at the following forum, you'll have an answer within 30 minutes (usually): forums.devnetwork.net/Yes, I think I know how to do it... spent some time on devnetwork reading posts last night... I would never dare ask as question on there about templates though; real hotbed issue! To template or to pure PHP... that's the question! I think I know how to do it both ways... it's more about me getting into PHP I suspect, as when you look at the code, it is very similar to everything else.
|
|
|
Post by sparrowhawk on Aug 10, 2004 10:27:29 GMT
That's what their "Advanced" forum is for - to ask questions about theory, best practice, concepts etc. I didn't realise that templates were so emotive!
|
|
merlin
Public Area Guest
Posts: 19
|
Post by merlin on Aug 11, 2004 23:24:06 GMT
I've got my first bit of php up on my site; www.icemark.com/writing/This page is now generated from a file and a template, as are all the story pages. Makes my submission process much much easier...
|
|