PHP Question...
- TOR_LordRaven
- DBB Ace
- Posts: 345
- Joined: Thu Nov 05, 1998 12:01 pm
PHP Question...
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!
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!
- TOR_LordRaven
- DBB Ace
- Posts: 345
- Joined: Thu Nov 05, 1998 12:01 pm
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.
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.
- TOR_LordRaven
- DBB Ace
- Posts: 345
- Joined: Thu Nov 05, 1998 12:01 pm
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.
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.
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:
Now, if you are trying to use text files as databases, then you are SOL...
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
?>
Re:
could always use access.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.
Re:
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
?>