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 5qFt3
Output for 7.2.0
string(29) "Carolina -6,5 - Indianapolis " Warning: Use of undefined constant text - assumed 'text' (this will throw an Error in a future version of PHP) in /in/XYpXB on line 4 string(4) "text" Notice: Undefined variable: team in /in/XYpXB on line 10 array(0) { } NULL Notice: Undefined variable: team in /in/XYpXB on line 13 array(0) { } NULL array(0) { } Notice: Undefined variable: team in /in/XYpXB on line 21 Notice: Undefined variable: team in /in/XYpXB on line 23 int(23) int(23)
Output for 7.1.0 - 7.1.10
string(29) "Carolina -6,5 - Indianapolis " Notice: Use of undefined constant text - assumed 'text' in /in/XYpXB on line 4 string(4) "text" Notice: Undefined variable: team in /in/XYpXB on line 10 array(0) { } NULL Notice: Undefined variable: team in /in/XYpXB on line 13 array(0) { } NULL array(0) { } Notice: Undefined variable: team in /in/XYpXB on line 21 Notice: Undefined variable: team in /in/XYpXB on line 23 int(23) int(23)
Output for 5.3.19 - 7.0.20
string(29) "Carolina -6,5 - Indianapolis " Notice: Use of undefined constant text - assumed 'text' in /in/XYpXB on line 4 string(4) "text" Notice: Undefined variable: team in /in/XYpXB on line 10 NULL NULL Notice: Undefined variable: team in /in/XYpXB on line 13 NULL NULL Warning: Invalid argument supplied for foreach() in /in/XYpXB on line 14 NULL Notice: Undefined variable: team in /in/XYpXB on line 21 Notice: Undefined variable: team in /in/XYpXB on line 23 int(23) int(23)