/    Sign up×
Community /Pin to ProfileBookmark

using php array’s for displaying pages

i had a website where i used a php array to display content in a particular table, but i cant remember how i done it and i have lost the old source files.

it worked so that i only had one php file that included the design of the pages and other html files with only the content. No design information was in those other html file.

the actual php code had things like

[code]‘contact’ => ‘contact.html’ ; ‘root’ => ‘home.html’[/code]

it had other bits like GET and things but i just cant remember.

say for example the index was called index.php when you directed the browser at index.php?p=contact it would take the content from the html file and put it in the table where the php code was;

I am greatful of any help recieved, thanks

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@violent_jApr 29.2004 — maybe something like:

[code=php]$valid_pages = array ("contact", "index", "home");
$p = $_GET["p"];
$valid = FALSE;
for ($x=0; $x<count($valid_pages); $x++) {
if ($p == $valid_pages[$x]) {
$valid = TRUE;
}
}
if ($valid) {
ob_start();
include ($p . ".html");
$contents = ob_get_contents();
ob_end_clean();
echo $contents;
}
else {
echo "invalid page";
}[/code]

i wrote this right out of hand, so there maybe some little bugz (syntax errors) in it, but basically this is the idea

grtz
Copy linkTweet thisAlerts:
@thekoreauthorApr 29.2004 — that definetly wasn't what i used before but i will give it a try thanks... still open to more suggestions on what i [i]did[/i] use before tho ?
Copy linkTweet thisAlerts:
@thekoreauthorApr 29.2004 — well that gave me a Parse error, so now i tried this:

[code=php]<?php
// This **** runs the content.
switch($_GET[p]) {
case content:
include ("content.html"); break;
default:
// Error checking
print "<b>ERROR</b>
<br />"$p" Does not exist.
<br />
<br />You may have entered an incorrect URL.
<br />Please refer back to the <a href="?p=root">Main Page</a> and try again.
";
break;
}
?>[/code]


and that is giving me Parse errors too ?
Copy linkTweet thisAlerts:
@thekoreauthorApr 29.2004 — ah this works now, it was my fault, but i would still apreciate info on what i might have done in the first instance or of any more effective ways of perfoming the same desired outcome

thanks ?
Copy linkTweet thisAlerts:
@violent_jApr 29.2004 — hmm .. i'm afraid i ran out of inspiration, but why bother looking for other options if this looks nice and works ??

grtz
Copy linkTweet thisAlerts:
@thekoreauthorApr 29.2004 — [i]Originally posted by violent j [/i]

[B]why bother looking for other options if this looks nice and works ??[/QUOTE]




i suppose you have a point :p
×

Success!

Help @thekore spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...