PT1M31S is a time format, means a time period of 1 minute and 31 seconds, then treat this string as a DateTime.
Create a new date and add this interval using the add () method, which takes as an argument DateInterval which is exactly the string
PT1M31S, done this just convert the 01:31 in seconds using date_parsed ()
$duracao = new DateTime('@0');
$duracao->add(new DateInterval('PT1M31S'));
$parsed = date_parse($duracao->format('H:i:s'));
$segundos = $parsed['hour'] * 3600 + $parsed['minute'] * 60 + $parsed['second'];
echo $segundos;
Or in a simplified way, create a DateInterval object to translate the time period into hours / minutes / seconds and then perform the calculation to convert these values in seconds. If I use this code in several places, I suggest that you change the values 3600
and 60
by constants to give more semantics, eg: const SEGUNDOS_EM_UMA_HORA = 3600
$intervalo = new DateInterval('PT1M31S');
$segundos = $intervalo->h * 3600 + $intervalo->i * 60 + $intervalo->s;
echo $segundos;
Based on:
Convert youtube Api v3 video duration in php
How to convert "HH: MM: SS" string to seconds with PHP?