Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loop timer with PHP

Tags:

php

I have a WEBVTT file connect with a video, the video length is about 120 minutes. The thumbnail tooptips of the video is running every second, which mean 120*60=7200 secs.

How to convert 7200 secs to WEBVTT format(hh:mm:ss.ttt) with php loop function? Example:

00:00:00.000 --> 00:00:01.000
00:00:01.000 --> 00:00:02.000
00:00:02.000 --> 00:00:03.000
00:00:03.000 --> 00:00:04.000    
and so on...    

Thanks!

like image 760
richard Avatar asked Jul 10 '26 09:07

richard


1 Answers

Using date():

date_default_timezone_set('UTC'); // To fix some timezone problems

$start = 0; // 0h
$end = 7200; // 2h
$output = '';

for($i=$start;$i<$end;$i++){
    $output .= date('H:i:s', $i).'.000 --> '.date('H:i:s', $i+1).'.000'.PHP_EOL;
}

echo $output;

Note that if $limit reaches 86400 it will start from 0 again.

like image 182
HamZa Avatar answered Jul 11 '26 23:07

HamZa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!