I have long texts in the database that contain subtitles formatted in the BBcode style, like that:[subtitle]part 1[/subtitle].
I then convert them into the html code:
$text = preg_replace("#\[subtitle\](.*?)\[/subtitle\]#si", "<a name=\"" . preg_replace("/\s+/", "", "\\1") . "\"><span class=\"subtitle\">\\1</span>", $text);
Here comes the first problem: I want to extract all subtitles from a text and put them into array in order to make a TOC for the text, something like this:
$subtitles = array('part 1', 'part 2', 'part 3', 'part 4');
The problem is, i have no idea on how this can be achieved and what function i should use. And another problem: I can't for the life of me strip the whitespace from the anchor name. 🙁 I guess i'm doing something wrong so any help is appreciated...