-
-
Save tommcfarlin/4458820d452c5d144dc26fc6f6b5ac12 to your computer and use it in GitHub Desktop.
[PHP] Split Strings and Integers in PHP Using Regular Expressions
This file contains 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 | |
$totalTimeParts = array_values( | |
array_filter( | |
preg_split("/(<=[0-9])*([a-zA-Z])/i", $totalTime) | |
) | |
); | |
if (isset($totalTimeParts[0]) && isset($totalTimeParts[1]) && '60' === $totalTimeParts[1]) { | |
$hours = (int)$totalTimeParts[0] + 1; | |
$minutes = '00'; | |
$totalTime = "P$hours" . 'H' . $minutes . 'M'; | |
} | |
return $totalTime; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment