title: Parse and create ISO 8601 Date and time intervals, like PT15M in PHP
body: <p>A library and webservice I am using communicates time-intervals in <a href="https://en.wikipedia.org/wiki/ISO_8601#Durations" rel="noreferrer">ISO 8601 format: <code>PnYnMnDTnHnMnS</code></a>. I want to convert such formats to seconds. And vice versa. Seconds are a lot easier to calculate with.</p>
  
  <p>Example interval values are: </p>
  
  <ul>
  <li>PT1M or PT60S (1 minute) </li>
  <li>PT1H, PT60M or PT3600S (1 hour)</li>
  </ul>
  
  <p>I need two functions: parse from such values to seconds: <code>iso8601_interval_to_seconds()</code> and from seconds into such intervals: <code>iso8601_interval_from_seconds()</code>.</p>
  
  <p>The latter is rather simple, because it could be done as `"PT{$seconds}S", just pass seconds along, at all times. Maybe this can be done nicer with a parser that switches to H(hour) or M(minute)? </p>
  
  <p>The first is harder, but maybe there is a trick with one of the many string-to-date converters in PHP? I would love to learn how to use such a function for parsing intervals. Or learn an alternative. </p>