PHP Format time containing letter in value

Asked

Viewed 37 times

-1

Example: 2h53m23s I’d like it to look like this:02:53:23

Example in my code

<?php 

valor_com_letra = "2h53m23s;

aqui a formatacao 


echo $valor_com_letra; //resultado 02:53:23



;?>

1 answer

4

A simple way is to replace these values

Ex

str_replace('s','', str_replace(['h','m'], ':', $valor_com_letra));
  • Perfect my friend thanks ta !

  • I have only one problem srrs when it comes to value : 58m26s I would like it to look like this 00:58:26

  • in case it gets like this: 58:26 then don’t enter the system understood

  • You can do an IF by checking the amount of characters. If it is 5 after treatment, you add 00: in front

Browser other questions tagged

You are not signed in. Login or sign up in order to post.