Code:
function getHeaders($content, $delimiter = '===') {
$tc = $content;
$titles = array();
while(strpos($content, $delimiter) !== false) {
$cttl = $tc;
$cttl = substr($cttl, strpos($cttl, $delimiter) + strlen($delimiter));
$cttl = substr($cttl, 0, strpos($cttl, $delimiter));
$cttl = trim($cttl);
array_push($titles, $cttl);
$tc = substr($tc, strlen($cttl) + strlen($delimiter));
}
return $titles;
}
function getSection($content, $section) {
$tc = $content;
$tc = substr($tc, strpos($tc, $section . ' ===') + 4);
$tc = substr($tc, 0, strpos($tc, '==='));
return $tc;
}
$fc = file_get_contents("file.txt");
$ttls = getHeaders($fc);
I wrote getSection() before I read your post properly, but figured you'd probably want it later on so I left it in there anyway.
Untested.
Bookmarks