with the name of the package you wish to install.
PEAR package manager now downloads and installs the specified package.
Semi-Automatic Installation:
Another way to install a package offline is putting the package in your PEAR dir.
Then run the following command:
$ pear install HTML_Page.tgz
This installs the package (downloaded as a .tgz) without needing to have an internet connection.
Manual Installation:
To install the package manually, let's put the package in /includes/
Use the following code to tell PHP where to look for our package:
<?php
ini_set(\"include_path\", '/var/www/www.example.com/includes/');
?>
Now we have set our include_path, we can simply require our package like this:
<?php
require_once 'HTML/Page.php';
?>
After installing HTML_Page, read on for the instructions on how to use it.
4. Using HTML_Page
This step of the tutorial will teach you the basics of HTML_Page and how to use it.
We will be learning:
- How to set up the doctype
- How to set meta and page title
- How to insert a stylesheet
- How to set body content and do output
Generating our page!
Below you will find the example code by PEAR. I will be explaining this bit by bit
so that you have an idea on how to use it.
<?php
require('HTML/Page.php');
$p = new HTML_Page(array (
'lineend' => 'unix',
'doctype' => 'XHTML 1.0 Strict',
'language' => 'en',
'cache' => 'false'
));
// Page title defaults to \"New XHTML 1.0 Strict Page\"
$p->setTitle(\"HTML_Page Color Chart example\");
$p->setMetaData(\"author\", \"Klaus Guenther\");
// Load a CSS
$p->addStyleSheet( './style.css' );
// let's add a Content-Type meta tag
$p->setMetaContentType();
$p->addBodyContent(\"<p>hello world</p>\");
// output to browser
$p->display();
// or to a file
//$p->toFile('example.html');
?>
First thing you should know is how to set the doctype and such.
$p = new HTML_Page(array (
'lineend' => 'unix',
'doctype' => 'XHTML 1.0 Strict',
'language' => 'en',
'cache' => 'false'
));
This will be initalizing the HTML_Page class. We tell it the line end, doctype and language.
Enabling cache is not recommended on really dynamic pages!!
// Page title defaults to \"New XHTML 1.0 Strict Page\"
$p->setTitle(\"Pear's HTML_Page Package Example\");
$p->setMetaData(\"author\", \"Cliff\");
This bit of code sets the title to Pear's HTML_Page Package Example.
You can set meta data using setMetaData().
// Load a CSS
$p->addStyleSheet( './style.css' );
This loads style.css from the current dir. There's not really much to explain.
// let's add a Content-Type meta tag
$p->setMetaContentType();
This actually initializes the meta content-type field.
$p->addBodyContent(\"hello world\");
The addBodyContent() function adds content into the body tag.. Use this function to
add any content to your page. Friendly reminder: You can't directly put text into when
doctype is XHTML. Put the text into a P or in a div to make it valid.
// output to browser
$p->display();
This prints the actual output, stored in the class, to the screen.
When you are done with generating the page, use this function to print the saved bits to the screen.
// or to a file
$p->toFile('example.html');
This bit of code saves the output to a .html file, usefull when trying to save things!
I hope you enjoyed reading this tutorial, actually learnt something and will put the knowledge to good use!
Tip of the day: You can use HTML_Page in combination with HTML_Template_IT, by doing $p->addBodyContent( $tpl->get );