Handle. srt files with PHP

Asked

Viewed 25 times

0

I am developing a project in Laravel 8 and this project consists of a SRT subtitle management system. In the world of subtitling teams divide an entire caption (srt file) into several slots. In other words, a srt file is divided into several srt files so that each team member is responsible for their part in question. That being said, I wanted to find a solution so that I could uple the entire file on the system, choose the number of slots in which it would be split and thus generate multiple srt files (derived from the main/entire file that I upeuped).

If I do this, it would prevent me from dividing the file manually and having to uproot 1 by 1.

A srt file follows this pattern:

inserir a descrição da imagem aqui

It has a type of ID (numbering), start/end time and legend. However, the legend can vary between 1 to 2 lines, which breaks the pattern a little.

I thought about doing the line counts and then manipulating based on the pattern, but it would become unviable because some have 1 or 2 lines as I mentioned earlier. Ex.:

<?php
$arquivo = fopen('meuarquivo.srt','r');
if ($arquivo == false) die('Não foi possível abrir o arquivo.');
while(true) {
    $linha = fgets($arquivo);
    if ($linha==null) break;
    echo $linha;
}
fclose($arquivo);
?>

Can anyone help me with a hint of how I could manipulate this in PHP and DB?

  • 1

    you can t using the RegExp for is including the formats or even checking these id without knowing where the values are positioned on each line

  • 1

    Is this blank line separation a pattern? If so, maybe to make a explode in the " n", more or less so explode("\n\n", file_get_contents('arquivo.srt')); the result must be an array where each element is a slot

  • Beforehand, thank you for the answers. That’s a pattern to this line separation in white. Ball show the idea, I’ll do some tests to see if it works.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.