Working with strings, numbers, and regular expressions in PHP is relatively easy given the vast number of functions the language provides.
There are times, though, where figuring out how to split on certain criteria may not be immediately clear, or it may be clear what you need to do but not how to best do it.

Photo by Agê Barros on Unsplash
For example, let’s say that you have a string that’s mixed with both numbers and digits. For this post, let’s say that a given string:
- includes hours and minutes,
- when the minutes are at 60,
- the string should increase the value of the of the hours by one
- the value of the minutes is reset to zero.
An example, problematic string, then, may be of the form T3H60M. How then might we split the string into strings and integers and properly rebuild it?