/** * Parse mp4chaps string into list of php maps. * * @param string $chapters_string */ public static function from_mp4chaps($chapters_string) { $chapters = new self(); $chapters_string = trim($chapters_string); foreach (preg_split("/((\r?\n)|(\r\n?))/", $chapters_string) as $line) { $valid = preg_match('/^((?:\\d+\\:[0-5]\\d\\:[0-5]\\d(?:\\.\\d+)?)|\\d+(?:\\.\\d+)?)(.*)$/', trim($line), $matches); if (!$valid) { continue; } $start = trim($matches[1]); $title = trim($matches[2]); $link = ''; $title = preg_replace_callback('/\\s?<[^>]+>\\s?/', function ($matches) use(&$link) { $link = trim($matches[0], ' < >'); return ' '; }, $title); $chapters->add_chapter(array('start' => $start, 'title' => $title, 'link' => $link)); } return $chapters; }