function buildTOC(&$text, $chapters, $parents = '')
{
global $chapters_elem;
$i=0;
$toc = '<div class="tabs-1"><ul class="tabs-nav clearfix">';
foreach($chapters as $chapter_raw => $subchapters)
{
$chapter = strip_tags(trim($chapter_raw));
$i++;
$elem = $chapters_elem[$chapter_raw];
$level = $parents.$i;
$url = $_SERVER["REQUEST_URI"] . "#tab$level";
$toc .= "<li><a href=\"$url\" title=\"$chapter\">$chapter</a>";
// $text = str_replace("<$elem>$chapter_raw</$elem>", "<div class=\"tab-content\" id=\"tab$level\"><div class=\"gamelist\"><$elem>$level. $chapter</$elem>", "");
//if (count($subchapters) > 0)
//{
// $toc .= buildTOC($text, $subchapters, $level.'.');
$text = str_replace("<$elem>$chapter_raw</$elem>", "<div class=\"tab-content\" id=\"tab$level\"><div class=\"gamelist\"><$elem>$level. $chapter</$elem>", $text);
// $text .= '</div></div>'; this does not work cause now it creates xx number, equal to the number of tabs cause it loop, of ending divs after the last tab text.
//}
$toc .= '</li>';
// $text .= '</div>'; this does not work cause now it creates xx number, equal to the number of tabs cause it loop, of ending divs after the last tab text.
}
$end .= '</div></div>';
$toc .= '</ul><div class="tabs-container">';
$text .= '</div></div>'; // this div closes the tabs-1 and the tabs-container div!
return $toc;
}
The thing is, I need to close 2 divs after each H3 tag and 4 after the last H3 tag.
I can not figure out where I need to place the code to close the 2 divs in the right position, I can make them close after the last H3 without issues but I need it after all H3 tags.