Page 1 of 1
PHP Question...
Posted: Fri Jun 27, 2008 8:41 am
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!
Posted: Fri Jun 27, 2008 9:00 am
by Krom
Don't use a HTML file, use a SQL database.
Posted: Fri Jun 27, 2008 9:07 am
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.
Posted: Fri Jun 27, 2008 10:13 am
by Krom
It definitely won't be any easier using a html file for it, even as a temporary test.
Posted: Fri Jun 27, 2008 1:35 pm
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.
Posted: Fri Jun 27, 2008 9:03 pm
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.
Posted: Sat Jun 28, 2008 12:32 am
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...
Re:
Posted: Sat Jun 28, 2008 1:04 am
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.
Re:
Posted: Sat Jun 28, 2008 10:30 am
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
?>
Posted: Sat Jun 28, 2008 1:25 pm
by Jeff250
empty(), that is going in my bag'o'tricks.