<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Simple PHP Tutorial</title>
</head>
<body>
<div id="nav">
<a href="./?page=home">Home</a>
<a href="./?page=test">Test</a>
<a href="./?page=about">About</a>
</div>
<?php
/* Get the current page being requested
Use strtolower() to make sure to lowercase the page, so (for example) "HOME" will be the same as "home"
In this tutorial, we'll also use an iif event () ? : to make sure that the default page
is "home". That way, when the page is loaded with no ?page= request, you will get the
"home" page content on the page.
!empty() checks to if the given variable returns null
*/
$page = strtolower(((!empty($_GET['page'])) ? $_GET['page'] : 'home'));
/* There are 2 ways of doing the next part.
One of which is a switch() { }
The other, is an if { } elseif() { } else { } statement
We're going to use the switch() {}
switch(variable) {
case <int|str>:
// Code you want to run here.
break;
default:
// If not other case is met, run this code.
break;
}
*/
switch($page) {
case "home":
/* Some people like to make arrays for the different bodies for pages. (Don't see the point in this.)
Some like to make whole new pages together, and then include() them.
Most people like to make their content dynamic, and use a MySQL database.
For this example, we're just going to make the content static.
*/
echo 'Your home page content.';
break;
default:
echo 'The page you requested does not exist.';
break;
}
?>
</body>
</html>
©2011, copyright BLACK BURN
0 comments:
Post a Comment