Allows you to easily manipulate every aspect of an html page while it is being created.
| Page | ( [ $title ] ) |
| doctype | ( [ $type [, $standard ]] ) |
| access | ( $user [, $level ] ) |
| eject | ( [ $url [, $message ]] ) |
| title | ( [ $title ] ) |
| description | ( $description ) |
| keywords | ( $keywords ) |
| robots | ( $allow ) |
| charset | ( $charset ) |
| link | ( $external_file [, $combine ] ) |
| body | ( $insert_tag ) |
| onload | ( $javascript_function ) |
| display | ( $html ) |
| An Advanced PHP for Beginners Example | |
| The (X)HTML Output | |
| Final Result | |
| object Page ( [ string $title ] ) | top |
Creates an (X)HTML page object.
<?php
$page = new Page ('Page Title');
?>
| doctype ( [ string $type= 'html' [, string $standard= 'strict' ]] ) | top |
This solves probably the stickiest situation that programmers face. The wave of the future is XHTML, yet no browser supports it (correctly) and have no plans to either. It is a better way to program in my opinion, but I like my code to look the same in all browsers (read IE), and so I code in XHTML yet deliver my code in HTML through this class. It converts the XHTML to HTML (and vice versa to an extent) so that I have perfect markup that validates with no errors. The doctype can be declared sitewide using a global variable so there is no need ever to use this method, unless you have your reasons. If your code doesn't meet the strict standard, then it automatically delivers the page as transitional (or loose) if you have 'center', 'u', 'font', or 'iframe' (deprecated) tags, and to frameset if you use 'frames'. So when Internet Explorer goes the way of Netscape (I see no other way), your code can be switched to XHTML in a heartbeat. Just put an 'x' in your global.
<?php
$page->doctype ('xhtml', 'transitional');
?>
| access ( string $user [, integer $level= 1 ] ) | top |
If you're particular about who views a certain page you can set permissions here.
<?php
$page->access ('users');
?>
| eject ( [ string $url [, string $message ]] ) | top |
This is a handy method for forms especially. It sends the user somewhere else if needed.
<?php
$page->eject ('sorry.html', "It's nothing personal.")
?>
| string title ( [ string $title ] ) | top |
Sets or changes the page title.
<?php
$page->title ('Advanced PHP for Beginners');
?>
| description ( string $description ) | top |
Sets the content for the meta description tag - default is the $page->title().
<?php
$page->description ('Jump start your programming.');
?>
| keywords ( string $keywords ) | top |
Sets the content for the meta keywords tag - default is the $page->title().
<?php
$page->keywords ('blazing speed easy to code ultimate reliability minimal knowledge');
?>
| robots ( bool $allow ) | top |
Tells the search engines if you would like them to crawl and index your page.
<?php
$page->robots (false);
?>
| charset ( string $charset ) | top |
If for whatever reason you want to change this, you can do so here.
<?php
$page->charset ('utf-8');
?>
| link ( string or array $external_file [, bool $combine= true ] ) | top |
The beauty of this method is that when you are dynamically creating content (the very purpose of PHP), and then realize you need something in the head section of your html, you can just put it there.
<?php
$page->link ('style.css');
$page->link (array('layout.css', 'style.css', 'fancy.js', 'favicon.ico')); // the duplicate style.css will be thrown out
$page->link ('<script type="text/javascript" src="http://maps.google.com/maps?file=api&v=2&key=' . $key . '"></script>');
?>
| body ( string $insert_tag ) | top |
Sometimes you just need to put something in the body tag. Well, here you go.
<?php
$page->body ('onload="googleMaps()" onunload="GUnload()"');
?>
| onload ( string or array $javascript_function ) | top |
This is to call multiple javascript functions after the page loads. Use as you would $page->link(). The only limitation is that you can't pass any variables with the functions, you can only submit the function name.
<?php
$page->onload (array('javaScriptFunction', 'startLoadingMoreImages'));
$page->onload ('throwUpPopUnders("Netflix", "casalemedia")'); // WRONG!! No parameters, remember? It was an annoying idea anyways.
?>
| string display ( string $html ) | top |
Returns the entire page, so this is the last function of all that you will call.
<?php
echo $page->display ($html);
?>
| An Advanced PHP for Beginners Example: | top |
<?php
$page = new Page;
$html = 'Hello World!';
echo $page->display ($html);
?>
| The (X)HTML Output: | top |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Advanced PHP for Beginners</title>
<meta name="description" content="Advanced PHP for Beginners">
<meta name="keywords" content="Advanced PHP for Beginners">
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
</head>
<body>
Hello World!
</body>
</html>| Final Result: | top |