3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $text = 'Carolina -6,5 - Indianapolis '; var_dump($text); $text = trim($text); var_dump($text); 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 XYpXB
Output for 7.1.0 - 7.2.0
string(29) "Carolina -6,5 - Indianapolis " string(28) "Carolina -6,5 - Indianapolis" array(6) { [0]=> string(28) "Carolina -6,5 - Indianapolis" [1]=> string(8) "Carolina" [2]=> bool(false) [3]=> bool(false) [4]=> string(4) "-6,5" [5]=> string(13) " Indianapolis" } int(1) array(0) { } int(1) array(0) { } Notice: Undefined offset: 4 in /in/JM5fo on line 22 int(23) int(23)
Output for 5.3.19 - 7.0.20
string(29) "Carolina -6,5 - Indianapolis " string(28) "Carolina -6,5 - Indianapolis" array(6) { [0]=> string(28) "Carolina -6,5 - Indianapolis" [1]=> string(8) "Carolina" [2]=> bool(false) [3]=> bool(false) [4]=> string(4) "-6,5" [5]=> string(13) " Indianapolis" } int(1) array(6) { [0]=> string(28) "Carolina -6,5 - Indianapolis" [1]=> string(8) "Carolina" [2]=> bool(false) [3]=> bool(false) [4]=> string(4) "-6,5" [5]=> string(13) " Indianapolis" } int(1) array(6) { [0]=> string(28) "Carolina -6.5 - Indianapolis" [1]=> string(8) "Carolina" [2]=> string(0) "" [3]=> string(0) "" [4]=> string(4) "-6.5" [5]=> &string(13) " Indianapolis" } float(16.5) int(23)