/** * Reads the subtitles from the given content * * @param string $p_content * @param string $p_firstSubtitle * @return array of MetaSubtitle */ public static function ReadSubtitles($p_content, $p_fieldName, $p_firstSubtitle = '', $p_headerFormatStart = null, $p_headerFormatEnd = null) { $result = preg_match_all('/('.MetaSubtitle::GetFindPattern().')/i', $p_content, $subtitlesNames); $contentParts = preg_split('/'.MetaSubtitle::GetSplitPattern().'/i', $p_content); $subtitlesContents = array(); foreach ($contentParts as $index=>$contentPart) { $name = $index > 0 ? $subtitlesNames[3][$index-1] : $p_firstSubtitle; if (empty($p_headerFormatStart)) { $formatStart = $index > 0 ? $subtitlesNames[2][$index-1] : ''; } else { $formatStart = $p_headerFormatStart; } if (empty($p_headerFormatEnd)) { $formatEnd = $index > 0 ? $subtitlesNames[4][$index-1] : ''; } else { $formatEnd = $p_headerFormatEnd; } $subtitles[] = new MetaSubtitle($index, $p_fieldName, count($contentParts), $name, $contentPart, $formatStart, $formatEnd); } return $subtitles; }