Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin
Created July 6, 2018 13:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tommcfarlin/4458820d452c5d144dc26fc6f6b5ac12 to your computer and use it in GitHub Desktop.
Save tommcfarlin/4458820d452c5d144dc26fc6f6b5ac12 to your computer and use it in GitHub Desktop.
[PHP] Split Strings and Integers in PHP Using Regular Expressions
<?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