Contents List Help

Ok yesterday i asked for help in my FAQ script and some one help me very well and iam successfully make the script but now i want to make List of contents just like in wikipedia My code is

[php]<?php
$str = “[H1]Top Heading[/H1] My test string [H2]My sub Heading[/H2] My second [H3]My deep Heading[/H3] string now again [H1]Top Heading[/H1] My test string [H2]My sub Heading[/H2] My second [H3]My deep Heading[/H3]”;

/**

  • Helper class
    */
    class FaqHelper {
    static $count = 1;
    static $listItems = array();
    static $prefix = ‘faq-’;

    static function GetList() {

     $items = '';
         foreach (self::$listItems as $id => $label) {
             $items .= '<li><a href="#' . self::$prefix . $id .'">' . $label . '</a></li>';
         }
    
     return '<ul>'. $items .'</ul>';
    

    }

    static function ReplaceCallback($matches)
    {
    $id = self::$count;
    $label = $matches[1];

     self::$listItems[$id] = $label;
    
     $res = '<font size=\"7"><span id=\"'. self::$prefix . $id .'">' . $label . '</span></font><hr />';
    
     self::$count++;
    
     return $res;
    

    }
    }

$text = preg_replace_callback(
“#[HD1]([^[]+)[/HD1]#”,
array(‘FaqHelper’, “ReplaceCallback”),
$str
);

$list = FaqHelper::GetList();

echo $list;
echo ‘

’;
echo $text;

?>
[/php]

and this gives

[code]1. Top Heading
2. Top Heading

Top Heading My test string [H2]My sub Heading[/H2] My second [H3]My deep Heading[/H3] string now again Top Heading My test string [H2]My sub Heading[/H2] My second [H3]My deep Heading[/H3][/code]

but i want this results

[code]1. Top Heading
1.1 My sub Heading
1.1.1 My deep Heading
2. Top Heading
2.1 My sub Heading
2.1.1 My deep Heading

Top Heading My test string My sub Heading My second My deep Heading string now again Top Heading My test string My sub Heading My second My deep Heading string now again[/code]

So on …

any idea or help?

Sponsor our Newsletter | Privacy Policy | Terms of Service