Travis Derouin wrote:
Hi,
Is there a function that already exists in the codebase that returns the # of sections in an article? I can't seem to find it. article::getSection takes a parameter for the ith section, but if you want to iterate over an article searching for a particular section, it's not clear how many sections there are. Similarily, it'd be great to have a function that return the section based on the section name, like getSectionByName or similar.
Travis
Hello Travis,
The parser does not report it. As sections are based on header, you can count the headers, this is done somewhere in the huge Parser::braceSubstitution method.
$m = preg_split( '/(^={1,6}.*?={1,6}\s*?$)/m', $text, -1, PREG_SPLIT_DELIM_CAPTURE );
Fromm there, count($m) gives you the number of heading and thus the number of section. You will have to play with that code a bit :)
cheers,