Location: PHPKode > scripts > Simple List > simple-list/listsimpleclass.php
<?php

/*

this class can create an html list like the obe below:

<h2>heading 1</h2>
<ul>
 <li>item one</li>
 <li>item two</li>
 <li>item three</li>
</ul>
<h2>heading 2</h2>
<ul>
 <li>item one</li>
 <li>item two</li>
 <li>item three</li>
</ul>

$headingstart e.g. <h1 id="check">
$headingend e.g. </h1>
$data 
 $data[]["h"] - heading item, e.g. chapter 1, chaper 2, chapter 3
 $data[]["i"] - list item,e.g. item1, item2, item3
$indents = the number of indents for the list

feel free to use anywhere, anytime, anyplace...

for more information, contact hide@address.com

*/


class listsimpleclass {

 function listsimpleclass($headingstart, $headingend, $data, $indents = 0) {
  $this->headingstart = $headingstart;
  $this->headingend = $headingend;
  $this->data = $data;
  $this->indents = $indents;
 }

 function createlist() {
  $headingex = '';
  foreach($this->data as $ds) {
   if($headingex != $ds["h"]) {
    $headingex = $ds["h"];
    if($i > 0) {
     $this->indents--;
     $v .= $this->addindents($this->indents).'</ul>';
    }
    $v .= $this->addindents($this->indents).$this->headingstart.$ds["h"].$this->headingend;
    $v .= $this->addindents($this->indents).'<ul>';
    $this->indents++;
   }
   $v .= $this->addindents($this->indents).'<li>'.$ds["i"].'</li>';
   $i++;
  }
  $this->indents--;
  $v .= $this->addindents($this->indents).'</ul>';
  return $v;
 }

 function addindents($indents) {
  return "\r\n".str_repeat(" ", $indents);
 }
}



?>
Return current item: Simple List