3v4l.org

run code in 300+ PHP versions simultaneously
<?php $h = ""; $rest = ""; $D = [0 => "zero","one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen", "twenty", 30 => "thirty", 40 => "forty", 50 => "fifty", 60 => "sixty", 70 => "seventy",80 => "eighty",90 => "ninety"]; function validate($x, $len) { $retval = null; if (!isset($x)){ echo "\$x is unset\n"; $retval = false; } else if (is_float($x) ){ echo "Floats are unsupported in this version.\n"; $retval = false; } else if ( $len == 0) { echo "Empty value\n"; $retval = false; } else if ( $x < 0) { echo "Negative numbers are currently unsupported.\n"; $retval = false; } else if ($len > 4) { echo "Numbers with more than 4 digits are unsupported\n"; $retval = false; } else { $retval = true; } return $retval; } function num2en( $x, $words) { $len = strlen($x); // Get number of digits in given number $retval = null; if( validate($x, $len) === false) { return false; } // handle number by length and digit(s) switch($len) { case 1: $retval = "$words[$x]\n"; break; case 2: if ( isset($words[$x]) ) { $retval = "$words[$x]\n"; } else if( preg_match('/^(.)(.)$/', $x, $matches ) ){ $retval = $words[ $matches[1] . '0'] . '-' . $words[ $matches[2]] . "\n"; } break; case 3: preg_match('/^(.)(..)$/',$x,$matches ); [$h, $rest] = [ $words[$matches[1]]." hundred", $matches[2] ]; if ( strcmp( $rest,'00') === 0 ) { $retval = $h; } if ($h == '0') { $retval = "and " . num2en(0 + $rest, $words); } $retval = $h . " and " . num2en( 0 + $rest, $words); break; case 4: $firstDigit = preg_split("//", $x, -1, PREG_SPLIT_NO_EMPTY )[0]; $retval = $words[$firstDigit] . " thousand " . num2en(substr($x,1,3), $words); break; } return $retval; } $bla; echo @num2en( $bla, $D ); echo num2en( -13, $D ); echo num2en( 1.5, $D ); echo num2en( 1, $D ); echo num2en( 10, $D ); echo num2en( 101, $D ); echo num2en( 1203, $D); echo num2en( 9999, $D); echo num2en( 19999, $D);
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
$x is unset Negative numbers are currently unsupported. Floats are unsupported in this version. one ten one hundred and one one thousand two hundred and three nine thousand nine hundred and ninety-nine Numbers with more than 4 digits are unsupported
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 $x is unset Negative numbers are currently unsupported. Floats are unsupported in this version. one ten one hundred and one one thousand two hundred and three nine thousand nine hundred and ninety-nine Numbers with more than 4 digits are unsupported
Output for 5.6.0 - 5.6.40, 7.0.0 - 7.0.33
Parse error: syntax error, unexpected '=' in /in/7gMlB on line 69
Process exited with code 255.

preferences:
264.47 ms | 402 KiB | 296 Q