PHP: How to convert string duration to ISO 8601 duration format? (ie. “30 minutes” to “PT30M”)
问题 There are plenty of questions asking how to do this the other way (converting from this format), but I cant find anything on how to output in the ISO 8601 duration format in PHP. So I have a heap of duration strings in human readable format - I want to convert them into the ISO 8601 format on the fly to print the durations for HTML5 microdata. Below is a sample of some of the strings coming in, and how they should be formatted "1 hour 30 minutes" --> PT1H30M "5 minutes" --> PT5M "2 hours" -->