Last active
November 25, 2015 23:11
-
-
Save bkralik/78be5b1b9056ecd80053 to your computer and use it in GitHub Desktop.
Mikrotik RouterOS time interval parser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function RouterOSparseInterval($in) { | |
| $pattern = "/(\d+)([wdhms])/"; | |
| $multipliers = array( | |
| "w" => 604800, | |
| "d" => 86400, | |
| "h" => 3600, | |
| "m" => 60, | |
| "s" => 1 | |
| ); | |
| preg_match_all($pattern, $in, $matches, PREG_SET_ORDER); | |
| $total = 0; | |
| foreach($matches as $m) { | |
| $total = $total + $m[1] * $multipliers[$m[2]]; | |
| } | |
| if(count($matches) == 0) { | |
| $total = -1; | |
| } | |
| return($total); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment