1 |
<?php |
2 |
|
3 |
/** |
4 |
* This example illustrates how to use the |
5 |
* HTMLPageClass to build a complete html |
6 |
* page. |
7 |
* |
8 |
* |
9 |
* $Id: example1.php,v 1.7 2003/07/28 16:47:42 hemna Exp $ |
10 |
* |
11 |
* @author Walter A. Boring IV <waboring@buildabetterweb.com> |
12 |
* @package phpHtmlLib |
13 |
* @subpackage examples |
14 |
* @version 2.0.0 |
15 |
* |
16 |
*/ |
17 |
|
18 |
/** |
19 |
* Include the phphtmllib libraries |
20 |
* All subsequent examples will use the |
21 |
* inlude_once("includes.inc"); which contains |
22 |
* the following 2 lines |
23 |
*/ |
24 |
$phphtmllib = $_SERVER["DOCUMENT_ROOT"] . "/phphtmllib"; |
25 |
include_once("$phphtmllib/includes.inc"); |
26 |
|
27 |
|
28 |
//create the page object |
29 |
|
30 |
//the first parameter is the title of the page. |
31 |
//this will automatically get placed inside the <title> |
32 |
//inside the head. |
33 |
|
34 |
//we want XHTML output instead of HTML |
35 |
//IF you want HTML output, then just leave off the |
36 |
//2nd parameter to the constructor. |
37 |
|
38 |
//Be default, phpHtmlLib will nicely indent all of the output |
39 |
//of the html source, to make it easy to read. If you want |
40 |
//all of the html source output to be left justified, then |
41 |
//pass INDENT_LEFT_JUSTIFY as the 3rd parameter. |
42 |
$page = new HTMLPageClass("phpHtmlLib Example 1 - Hello World", |
43 |
XHTML_TRANSITIONAL); |
44 |
|
45 |
//if you want phphtmllib to render the |
46 |
//output as viewable source code |
47 |
//then add ?debug=1 to the query string to this script |
48 |
if (isset($_GET['debug'])) { |
49 |
$page->set_text_debug( TRUE ); |
50 |
} |
51 |
|
52 |
|
53 |
|
54 |
//add the obligitory hello world |
55 |
//calling the add method will add the object |
56 |
//into the page. It will get rendered when |
57 |
//you call the HTMLPageClass' render() method. |
58 |
$page->add( html_span(NULL, "hello world"), html_br(2) ); |
59 |
|
60 |
//note the calls to the 2 helper functions |
61 |
//html_span() and html_br() These are wrapper |
62 |
//functions for constructing tags and adding common |
63 |
//attributes, along with content. |
64 |
// All of the helper functions live in phphtmllib/tag_utils |
65 |
//html_span() takes a string as the first parameter |
66 |
//which will set the class="something" attribute |
67 |
//any n number of parameters after that will be |
68 |
//added to the content of the tag. |
69 |
|
70 |
//html_br() builds a <br> tag. The parameter is |
71 |
//how many <br>'s to build. |
72 |
|
73 |
|
74 |
//lets add a simple link to this script |
75 |
//and turn debugging on |
76 |
$page->add( html_a($_SERVER["PHP_SELF"]."?debug=1", "Show Debug source") ); |
77 |
|
78 |
|
79 |
//this will render the entire page |
80 |
//with the content you have added |
81 |
//wrapped inside all the required |
82 |
//elements for a complete HTML/XHTML page. |
83 |
//NOTE: all the objects in phphtmllib have |
84 |
// the render() method. So you can call |
85 |
// render on any phphtmlib object. |
86 |
print $page->render(); |
87 |
?> |