PHP code example of lsv / timestringparser

1. Go to this page and download the library: Download lsv/timestringparser 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/ */

    

lsv / timestringparser example snippets


$timestrings = [
    '3:20', '1h 42m', '1u 22x', '3u55x',
    20, '1h', '48h84y', '3t994x'
];
$parser = new TimestringParser(['h','t','u'], ['m','x','y']);
foreach($timestrings as $string) {
    echo $parser->parseTimeString($string); // Return integers
}

$timestrings = [1, 2, '3', '4', 5];
$parser = new TimestringParser(['h'], ['m'], 3);
echo $parser->parseTimeString(1); // Returns 60
echo $parser->parseTimeString(2); // Returns 120
echo $parser->parseTimeString('3'); // Returns 180
echo $parser->parseTimeString('4'); // Returns 4
echo $parser->parseTimeString(5); // Returns 5