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
and this givesPHP Code:<?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 '<br /><br />';
echo $text;
?>
but i want this resultsHTML 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]
So on ...HTML 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
any idea or help?



Reply With Quote
Bookmarks