1. Go to this page and download the library: Download hartman/vtt-vivid 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/ */
hartman / vtt-vivid example snippets
use WebVTT\VttReader;
// Load the WebVTT file
$vttFile = 'path/to/your/file.vtt';
$reader = VttReader::fromFile($vttFile);
$reader->setStrict(true);
try {
$reader->parse();
echo "The WebVTT file is strictly valid.\n";
} catch (Exception $e) {
echo "Strict validation failed: " . $e->getMessage() . "\n";
}
use WebVTT\VttWriter;
use WebVTT\DOM\VttCue;
use WebVTT\DOM\VttFile;
// Create a new VttFile instance
$vttFile = new VttFile();
// Add a cue to the file (start time, end time, text)
$cue = new VttCue(1.0, 4.0, 'Hello, world!');
$vttFile->addBlock($cue);
// Write the file to disk
$outputFile = 'path/to/output/file.vtt';
$writer = new VttWriter($vttFile);
$writer->write($outputFile);
echo "Subtitle file created at $outputFile\n";
use WebVTT\DOM\VttCue;
use WebVTT\DOM\CueText\AnnotatedElementNode;
$cue = new VttCue(0.0, 5.0, '<v Bob>Hello <b>there</b></v>');
foreach ($cue->getContentNodes() as $node) {
if ($node instanceof AnnotatedElementNode) {
echo $node->getAnnotation(); // "Bob"
}
}
$cue = new VttCue(0.0, 5.0, '');
$cue->setContentNodes([ new TextNode('A & B'), new ElementNode(CueTag::BOLD) ]);
echo $cue->toCueText(); // "A & B<b></b>"
use WebVTT\Parser\CueTextParser;
use WebVTT\Validation\CallbackValidationReporter;
$warnings = [];
$parser = new CueTextParser(new CallbackValidationReporter(
function (string $w) use (&$warnings) { $warnings[] = $w; }
));
$nodes = $parser->parse('<c.green>hi</span>');
// $warnings now describes the colour hint and the unauthorized </span>
bash
composer fix
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.