Learner\Services\Videos\Youtubee::formatDuration PHP Method

formatDuration() private method

Format the duration.
private formatDuration ( string $duration ) : integer
$duration string
return integer
    private function formatDuration($duration)
    {
        preg_match_all("/PT(\\d+H)?(\\d+M)?(\\d+S)?/", $duration, $matches);
        $hours = strlen($matches[1][0]) == 0 ? 0 : substr($matches[1][0], 0, strlen($matches[1][0]) - 1);
        $minutes = strlen($matches[2][0]) == 0 ? 0 : substr($matches[2][0], 0, strlen($matches[2][0]) - 1);
        $seconds = strlen($matches[3][0]) == 0 ? 0 : substr($matches[3][0], 0, strlen($matches[3][0]) - 1);
        return 3600 * $hours + 60 * $minutes + $seconds;
    }