PHP Question...

For system help, all hardware / software topics NOTE: use Coders Corner for all coders topics.

Moderators: Krom, Grendel

Post Reply
User avatar
TOR_LordRaven
DBB Ace
DBB Ace
Posts: 345
Joined: Thu Nov 05, 1998 12:01 pm

PHP Question...

Post by TOR_LordRaven »

I have a simple PHP Question..
Ive been working with PHP for a while now, but can't get this simple script to work.

I want to create 1 file, lets call it \"numbers.php\".

It will be a template file that calls to another htm file.

I have several htm files like, \"work.htm\", \"family.htm\", \"friends.htm\".

What I want to do is have \"numbers.php\" open \"work.htm\" within itself (nubmers.php being the template file and work.htm being the actual content) but w/o creating individual php files for each htm file.

Does that make sense?

maybe something like...

\"numbers.php?display=work\" and whatever comes after \"display=\" it will auto call a htm file and display it in a specified part of the php file.


im not looking to build a huge template driven system, just something simple to accomplish a small task - so any ideas would be appriciated!
User avatar
Krom
DBB Database Master
DBB Database Master
Posts: 16137
Joined: Sun Nov 29, 1998 3:01 am
Location: Camping the energy center. BTW, did you know you can have up to 100 characters in this location box?
Contact:

Post by Krom »

Don't use a HTML file, use a SQL database.
User avatar
TOR_LordRaven
DBB Ace
DBB Ace
Posts: 345
Joined: Thu Nov 05, 1998 12:01 pm

Post by TOR_LordRaven »

i will move it to a database sooner or later...

but for now, id like to try this with htm files first.
User avatar
Krom
DBB Database Master
DBB Database Master
Posts: 16137
Joined: Sun Nov 29, 1998 3:01 am
Location: Camping the energy center. BTW, did you know you can have up to 100 characters in this location box?
Contact:

Post by Krom »

It definitely won't be any easier using a html file for it, even as a temporary test.
User avatar
fliptw
DBB DemiGod
DBB DemiGod
Posts: 6459
Joined: Sat Oct 24, 1998 2:01 am
Location: Calgary Alberta Canada

Post by fliptw »

You are better off saving them in a comma separated file. HTML is not a good method of storing data. Unless you like messing around HTML parsers.

Krom suggestion is the logical one, however. That gives you more flexibility, like adding values, changing them, and having the SQL server do some math work for you.
User avatar
TOR_LordRaven
DBB Ace
DBB Ace
Posts: 345
Joined: Thu Nov 05, 1998 12:01 pm

Post by TOR_LordRaven »

Thats kindof the idea.

In this situation, having an SQL backend is not possible at the moment. This is for a local intranet, and they don't want to deal with a database.

I figured having individual htm files to hold the content and a single php file to call them would be simple enough - but looks like its not.
User avatar
Jeff250
DBB Master
DBB Master
Posts: 6539
Joined: Sun Sep 05, 1999 2:01 am
Location: ❄️❄️❄️

Post by Jeff250 »

What do you mean \"to call the html files\"? Perhaps I'm oversimplifying the problem, but if each html page is a singular blob of html content that you want wholly included into a template, then something like this should do as you desire:

Code: Select all

<?php

isset($_GET['display']) && $_GET['display'] or die('No page requested.');

$page = $_GET['display'];

switch($page) {
case 'foo': $html = 'foo.html'; break;
case 'bar': $html = 'bar.html'; break;
case 'gah': $html = 'gah.html'; break;
default: die('Page '.htmlspecialchars($page).' not found.');
}

// crap on top goes here

include($html);

// crap on bottom goes here

?>
Now, if you are trying to use text files as databases, then you are SOL...
User avatar
fliptw
DBB DemiGod
DBB DemiGod
Posts: 6459
Joined: Sat Oct 24, 1998 2:01 am
Location: Calgary Alberta Canada

Re:

Post by fliptw »

TOR_LordRaven wrote: In this situation, having an SQL backend is not possible at the moment. This is for a local intranet, and they don't want to deal with a database.
could always use access.
User avatar
heftig
DBB Ace
DBB Ace
Posts: 138
Joined: Mon Jun 05, 2006 9:55 pm
Location: Germany
Contact:

Re:

Post by heftig »

If you want it a bit more flexible (without having to edit numbers.php when adding/deleting pages), you can give all the html files alphanumeric names and put them in a subfolder and do this:

Code: Select all

<?php

if (empty($_GET['display']) die('No page requested.');

$page = $_GET['display'];

if (!ctype_alnum($page)) die('Invalid page requested.');

$page = \"pages/${page}.html\";

if (!file_exists($page)) die(\"Page \\\"$page\\\" not found.\");

// crap on top goes here

require($page);

// crap on bottom goes here

?>
User avatar
Jeff250
DBB Master
DBB Master
Posts: 6539
Joined: Sun Sep 05, 1999 2:01 am
Location: ❄️❄️❄️

Post by Jeff250 »

empty(), that is going in my bag'o'tricks. :D
Post Reply