Advanced PHP for Beginners

Lister Class

Makes creating ordered, unordered, definition and custom html lists as easy as drawing a circle on a piece of paper.

Download Now!
Lister
ordered ( $list [, $enclose ] )
unordered ( $list [, $enclose ] )
definition ( $list )
custom ( $delimit, $list [, $begin [, $end [, $enclose ]]] )
An Advanced PHP for Beginners Example
The (X)HTML Output
Final Result
object Listertop

Creates a new list object.

Example:
<?php

$list 
= new Lister;

?>
string ordered ( array $list [, array $enclose ] )top

Creates an ordered list from the array $list.

$list:
The array with which to create an ordered list. Can either be multi-dimensional, or as in the example below.
$enclose:
An array of html tags such as 'b', 'big', 'i' etc. that you want to enclose every list item with. Of course I recommend using a style sheet, but this option is available.
Returns:
A string of code to add to your $html.
Example:
<?php

$li
[] = 'List';
$li[][] = 'Item 1';
$li[][] = 'Item 2';
$li[][][] = 'Sub Item 2';
$li[] = 'More';

/* The above array's multi-dimensional counterpart would be:
$li[0] = array(1=>'List', 5=>'More');
$li[1] = array(2=>'Item 1', 3=>'Item 2');
$li[3] = array(4=>'Sub Item 2');
*/

$html .= $list->ordered ($li, array('b''i'));

?>
string unordered ( array $list [, array $enclose ] )top

Creates an unordered list from the array $list.

$list:
The array with which to create an ordered list. Can either be multi-dimensional, or as in the example above.
$enclose:
An array of html tags that you would like to enclose every list item with.
Returns:
A string of code to add to your $html.
Example:
<?php

$html 
.= $list->unordered ($li);

?>
string definition ( array $list )top

Creates a definition list from the array $list. This method does not have the enclose option.

$list:
This array is going to be different than the ones we made for our ordered and unordered lists. All we need are name and value pairs, so the name is the arrays key, and it's value is the array keys value.
Returns:
A string of code to add to your $html.
Example:
<?php

$def
['efficiency'] = 'making good, thorough, or careful use of resources; not consuming extra. Especially, making good use of time or energy';
$def['harmonious'] = 'a pleasing combination of elements';
$def['organized'] = 'methodical and efficient in arrangement or function; formed into a structured or coherent whole';

$html .= $list->definition ($def);

?>
string custom ( string $delimit, array $list [, string $begin [, string $end [, array $enclose ]]] )top

This method allows you to create a custom list in case you don't like the flavors that html offers you.

$delimit:
This is what you would like to indent each line with - spaces, tabs, smiley faces etc.
$list:
Your custom list's array. Can either be multi-dimensional, or as in the example above.
$begin:
Different from delimit in that it doesn't multiply itself, so this is where you would put your dash, checkmark.gif, multicheck form box, etc.
$end:
What you want at the end of the line - a <br /> tag most likely.
$enclose:
An array of html tags that you would like to enclose every list item with.
Returns:
A string of code to add to your $html.
Example:
<?php

$html 
.= '<pre>' $list->custom ("\t"$li'- ''<br />') . '</pre>';

?>
An Advanced PHP for Beginners Example:top
<?php

$page 
= new Page;
$page->link('style.css');
$html '';

$list = new Lister;

$li[] = 'List';
$li[][] = 'Item 1';
$li[][] = 'Item 2';
$li[][][] = 'Sub Item 2';
$li[] = 'More';

$html .= $list->ordered ($li, array('b''i'));

$html .= $list->unordered ($li);

$html .= '<pre>' $list->custom ("\t"$li'- ''<br />') . '</pre>';

$def['efficiency'] = 'making good, thorough, or careful use of resources; not consuming extra. Especially, making good use of time or energy';
$def['harmonious'] = 'a pleasing combination of elements';
$def['organized'] = 'methodical and efficient in arrangement or function; formed into a structured or coherent whole';

$html .= $list->definition ($def);

unset (
$list);

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">
  <link rel="stylesheet" type="text/css" href="http://www.advancedphpforbeginners.com/combine/style.css">
</head>
<body>
  
  <ol>
  <li><b><i>List</i></b>
    <ol>
    <li><b><i>Item 1</i></b></li>
    <li><b><i>Item 2</i></b>
      <ol>
      <li><b><i>Sub Item 2</i></b></li>
      </ol></li>
    </ol></li>
  <li><b><i>More</i></b></li>
  </ol>
  <ul>
  <li>List
    <ul>
    <li>Item 1</li>
    <li>Item 2
      <ul>
      <li>Sub Item 2</li>
      </ul></li>
    </ul></li>
  <li>More</li>
  </ul><pre>
  	- List<br>
    		- Item 1<br>
    		- Item 2<br>
      			- Sub Item 2<br>
  	- More<br></pre>
  <dl>
    <dt>efficiency</dt>
      <dd>making good, thorough, or careful use of resources; not consuming extra. Especially, making good use of time or energy</dd>
    <dt>harmonious</dt>
      <dd>a pleasing combination of elements</dd>
    <dt>organized</dt>
      <dd>methodical and efficient in arrangement or function; formed into a structured or coherent whole</dd>
  </dl>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        </body>
</html>
Final Result:top
Bookmark This Page
Home
Download
Contact Us