3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $inputString = "80"; $pattern = '/[ \-]/'; $replacement = ''; $inputString = preg_replace($pattern,$replacement,$inputString); $inputString = trim($inputString); $count = strlen($inputString); //echo $inputString;exit; $rem = ($count%3); if ($rem == 1){ $pos =4; $count = ($count - $pos); } else if($rem == 2) { $pos = 2; $count = ($count - $pos); } $phoneNumber = ""; for($k=0;$k<$count;$k++){ if($k % 3 !=0 || $k == 0){ $phoneNumber = $phoneNumber.$inputString[$k]; $phoneNumber = trim($phoneNumber); }else{ $phoneNumber = $phoneNumber.'-'.$inputString[$k]; } } //echo $phoneNumber;exit; if($rem == 2); if($count!=0){ $phoneNumber.='-'; } $phoneNumber.= $inputString[$count].$inputString[$count+1]; }else if($rem == 1){ if($count!=0){ $phoneNumber.='-'; } $phoneNumber.= $inputString[$count].$inputString[$count+1].'-'.$inputString[$count+2].$inputString[$count+3]; } echo $phoneNumber;exit;
based on ua29Q
Output for 7.0.0
Parse error: syntax error, unexpected '}', expecting end of file in /in/rOIl0 on line 39
Process exited with code 255.
Output for 5.3.20 - 5.6.16
Parse error: syntax error, unexpected '}' in /in/rOIl0 on line 39
Process exited with code 255.