iamdual/srt-parser

SRT (SubRip文本) 解析器库。

0.1.1 2022-07-20 12:36 UTC

This package is auto-updated.

Last update: 2024-09-20 17:12:58 UTC


README

PHP 8编写的另一个SRT (SubRip文本) 解析器库。

安装

composer require iamdual/srt-parser

使用

$parser = SrtParser::fromFile(__DIR__ . '/MrRobot.srt');
foreach ($parser->getSubtitles() as $subtitle) {
    echo $subtitle->getContent();
}

为了高级用途,您可以使用子类代替门面。

$content = file_get_contents(__DIR__ . '/MrRobot.srt');
$chunks = new Chunks($content);
foreach ($chunks->getChunks() as $chunk) {
    $parser = new SubtitleParser($chunk);
    try {
        $subtitle = $parser->getSubtitle();
        var_dump($subtitle);
    } catch (SyntaxErrorException $e) {
        echo 'Error! ' . $e->getMessage();
        continue;
    }
}

更多信息

作者