3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $text = 'Carolina -6,5 - Indianapolis '; if (mb_ereg('^(.+)[[:space:]]+(([-]?[0-9]+[,.]?[0-9]*) /)?([-]?[0-9]+[,.]?[0-9]*)? -(.+)$', $text, $ar)) $team = 1; var_dump($ar, $team); if (mb_ereg('^(.+) -(.+)[[:space:]]+(([-]?[0-9]+[,.]?[0-9]*) /)?([-]?[0-9]+[,.]?[0-9]*)?$', $text, $ar)) $team = 2; var_dump($ar, $team); foreach ($ar as $key => &$a) $a = str_replace(array(",", "+"), array(".", ""), $a); var_dump($ar); $home = 23; $away = 23; if ($team == 1) $home = $home + $ar[4]; elseif ($team == 2) $away = $away + $ar[5]; var_dump($home, $away);
based on aYCjV
Output for 7.1.0 - 7.2.0
array(6) { [0]=> string(29) "Carolina -6,5 - Indianapolis " [1]=> string(8) "Carolina" [2]=> bool(false) [3]=> bool(false) [4]=> string(4) "-6,5" [5]=> string(14) " Indianapolis " } int(1) array(6) { [0]=> string(29) "Carolina -6,5 - Indianapolis " [1]=> string(13) "Carolina -6,5" [2]=> string(13) " Indianapolis" [3]=> bool(false) [4]=> bool(false) [5]=> bool(false) } int(2) array(6) { [0]=> string(29) "Carolina -6.5 - Indianapolis " [1]=> string(13) "Carolina -6.5" [2]=> string(13) " Indianapolis" [3]=> string(0) "" [4]=> string(0) "" [5]=> &string(0) "" } Warning: A non-numeric value encountered in /in/5qFt3 on line 20 int(23) int(23)
Output for 5.5.0 - 7.0.20
array(6) { [0]=> string(29) "Carolina -6,5 - Indianapolis " [1]=> string(8) "Carolina" [2]=> bool(false) [3]=> bool(false) [4]=> string(4) "-6,5" [5]=> string(14) " Indianapolis " } int(1) array(6) { [0]=> string(29) "Carolina -6,5 - Indianapolis " [1]=> string(13) "Carolina -6,5" [2]=> string(13) " Indianapolis" [3]=> bool(false) [4]=> bool(false) [5]=> bool(false) } int(2) array(6) { [0]=> string(29) "Carolina -6.5 - Indianapolis " [1]=> string(13) "Carolina -6.5" [2]=> string(13) " Indianapolis" [3]=> string(0) "" [4]=> string(0) "" [5]=> &string(0) "" } int(23) int(23)