PHP Classes

File: Usage

Recommend this page to a friend!
  Classes of Niels Nielsen   HTMList   Usage   Download  
File: Usage
Role: Example script
Content type: text/plain
Description: Shows the basic of using the HTMList
Class: HTMList
Create and manipulate HTML output programaticallly
Author: By
Last change:
Date: 14 years ago
Size: 1,190 bytes
 

Contents

Class file image Download
<?php
   
   
require_once("htmlist.php");
   
   
//Prepare some HTML content
   
$ul = array(
       
"<ul>",
        array(
           
"<li>One</li>",
           
"<li>Two</li>",
           
"<li>Three</li>"
       
),
       
"</ul>"
   
);
   
   
//Create a new list using the content array
   
$a = new HTMList($ul);
   
   
//Insert content at the beginning
   
$a -> add_before("<span>As easy as:</span><br />");
   
   
//Using labeled content
   
$a -> add_after(array("footnote"=>array("<i>This goes after everything else.</i>")));
   
   
//Add a div around "footnote" and call it wrapper
   
$a -> add_around("<div>", "</div>", "footnote", "wrapper");
   
   
   
//Prepare some CSS
   
$css = array(
       
"div {",
        array(
           
"background: #ff0080;"
       
),
       
"}"
   
);
   
   
//Make a new HTMList with it
   
$b = new HTMList();
   
$b -> add_css_before($css);
   
   
//Add the obj with the CSS to our first obj
   
$a -> add_before($b);
   
   
//Debug:
    //print_r($a);
   
    //Final output
   
$a -> str(true);
   
   
/*
        <style>

            div {
                background: #ff0080;
            }

        </style>
        <span>As easy as:</span><br />
        <ul>
            <li>One</li>
            <li>Two</li>
            <li>Three</li>
        </ul>
        <div>
            <i>This goes after everything else.</i>
        </div>
    */
   
   
?>