3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function atoi($s){ $s = trim($s); $sign = '+'; if($s[0]=='+'||$s[0]=='-'){ $sign = $s[0]; } if(!ctype_digit($s[1])) { return 0; } $s = preg_replace('/[^0-9]/','',$s); if($s) { if($sign=='-') { $s = -$s; } } else { $s = 0; } return $s; } var_dump(atoi("303819")); var_dump(atoi('-303')); var_dump(atoi('293kurwa')); var_dump(atoi('kurwa 552')); var_dump(atoi('+29')); var_dump(atoi('- 69')); var_dump(atoi('ja pierdole')); // :( var_dump(atoi('3fail3'));
based on CF3em
Output for 4.3.0 - 7.2.0
string(6) "303819" int(-303) string(3) "293" int(0) string(2) "29" int(0) int(0) int(0)