| 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.6 2002/09/26 21:29:06 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 | $page->set_text_debug( $_GET["debug"] ); | 
| 49 |  | 
| 50 |  | 
| 51 | //add the obligitory hello world | 
| 52 | //calling the add method will add the object | 
| 53 | //into the page.  It will get rendered when | 
| 54 | //you call the HTMLPageClass' render() method. | 
| 55 | $page->add( html_span(NULL, "hello world"), html_br(2) ); | 
| 56 |  | 
| 57 | //note the calls to the 2 helper functions | 
| 58 | //html_span() and html_br()  These are wrapper | 
| 59 | //functions for constructing tags and adding common | 
| 60 | //attributes, along with content. | 
| 61 | // All of the helper functions live in phphtmllib/tag_utils | 
| 62 | //html_span() takes a string as the first parameter | 
| 63 | //which will set the class="something" attribute | 
| 64 | //any n number of parameters after that will be | 
| 65 | //added to the content of the tag. | 
| 66 |  | 
| 67 | //html_br() builds a <br> tag.  The parameter is | 
| 68 | //how many <br>'s to build. | 
| 69 |  | 
| 70 |  | 
| 71 | //lets add a simple link to this script | 
| 72 | //and turn debugging on | 
| 73 | $page->add( html_a($_SERVER["PHP_SELF"]."?debug=1", "Show Debug source") ); | 
| 74 |  | 
| 75 |  | 
| 76 | //this will render the entire page | 
| 77 | //with the content you have added | 
| 78 | //wrapped inside all the required | 
| 79 | //elements for a complete HTML/XHTML page. | 
| 80 | //NOTE: all the objects in phphtmllib have | 
| 81 | //      the render() method.  So you can call | 
| 82 | //      render on any phphtmlib object. | 
| 83 | print $page->render(); | 
| 84 | ?> |