PHP code example of saeven / subtitles

1. Go to this page and download the library: Download saeven/subtitles 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/ */

    

saeven / subtitles example snippets


// add namespace
use \Circlical\Subtitles\Subtitles;

(new Subtitles())->load($srtContent, 'srt')->content('vtt');

$subtitles = new Subtitles();
$subtitles->add(0, 5, 'This text is shown in the beggining of video for 5 seconds');
file_put_contents( './foo', $subtitles->content('subtitles.vtt'));

$string = "
1
00:02:17,440 --> 00:02:20,375
Senator, we're making our final approach
";  

$subtitles = Subtitles::load($string, 'srt');

echo $subtitles->content('vtt');

$subtitles->add(0, 5, 'some text'); // from 0, till 5 seconds  

// Add multiline text
$subtitles->add(0, 5, [
    'first line',
    'second line',
]);

$subtitles->remove(0, 5); // from 0, till 5 seconds

$subtitles->shiftTime(1);

$subtitles->shiftTime(-0.5);

$subtitles->shiftTime(5, 60, 120);

$subtitles->shiftTimeGradually(2, 0, 3600);
vtt
WEBVTT

00:00:00.976 --> 00:00:03.904 align:center line:90%
[MUSIC PLAYING]