Sunday, 14 June 2015

Parse YouTube Time Code PHP

Parse YouTube Time Code PHP





I am sharing my PHP code to parse YouTube time.


<?php

function covtime($youtube_time)
{
    $start = new DateTime('@0'); // Unix epoch
    $start->add(new DateInterval($youtube_time));
    return $start->format('g:i:s');
}
echo date("H:i:s");
echo "<br>";
echo covtime('PT2H34M25S'); // => 2:34:25
echo "<br>";
echo date("H:i:s");
echo "<br>";
preg_match_all('/(\d+)/', "PT2H34M25S", $parts);
echo "<br>";
echo date("H:i:s");
echo "<pre>";
print_r($parts);

?>

No comments:

Post a Comment

Create .ICS file using PHP code

Recently worked on creating a .ics file in PHP after a very long time, code so thought to share with everybody. Please find below the comple...