PHP code example of iamdual / srt-parser

1. Go to this page and download the library: Download iamdual/srt-parser library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

iamdual / srt-parser example snippets


$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;
    }
}