3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $time = "31d2h54"; $minutes = 0; $days = 0; $hours = 0; function lastinteger($string) { preg_match_all('((\d)+)',$string,$array); echo "Taille du tableau trouve : " . count($array); // echo PHP_EOL, "CHaine du last integer " . $array[0] , PHP_EOL; echo PHP_EOL, "var dump : " . var_dump($array[0]) ,PHP_EOL; $out = end($array); return $out[0]; } $length = strlen($time); $positionDays = strpos($time, "d"); echo $positionDays . ": Position des jours "; $positionHours = strpos($time, "h"); echo $positionHours . ": Position des heures "; $positionMinutes = strpos($time, "m"); echo $positionMinutes . ": Position des Minutes ", PHP_EOL; if ($positionDays === false) { } else { if (is_numeric(substr($time, $positionDays + 1 , $length - 1))) { $days += (intval(substr($time, $positionDays + 1, $length - 1)) / 60); } $days += lastinteger(substr($time, 0, $positionDays)); } if ($positionHours === false) { } else { if (is_numeric(substr($time, $positionHours + 1 , $length - 1))) { $hours += (intval(substr($time, $positionHours + 1, $length - 1)) / 60); } echo "chaine envoyé " . substr($time, 0, $positionHours), PHP_EOL; $hours += lastinteger(substr($time, 0, $positionHours)); } if ($positionMinutes === false) { } else { if(is_numeric(substr($time,$positionMinutes + 1,$length -1))) { $minutes += (intval(substr($time,$positionMinutes + 1,$length -1)) / 60); } $minutes += lastinteger(substr($time,0,$positionMinutes)); } echo "Temps : "; echo $minutes . " minutes "; echo $hours . " heures "; echo $days . " jours ";
based on ZlCAO
Output for 5.6.0 - 5.6.30, hhvm-3.18.5 - 3.22.0, 7.1.0 - 7.3.0beta1
2: Position des jours 4: Position des heures : Position des Minutes Taille du tableau trouve : 2 array(1) { [0]=> string(2) "31" } var dump : chaine envoyé 31d2 Taille du tableau trouve : 2 array(2) { [0]=> string(2) "31" [1]=> string(1) "2" } var dump : Temps : 0 minutes 1.9 heures 1 jours