3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getCode($string) { $code = 0; if (preg_match('/\bred\b/i', $string)) { $code += 2; } if (preg_match('/\bblue\b/i', $string)) { $code += 3; } if (preg_match('/\bgreen\b/i', $string)) { $code += 4; } if ($code === 9) { $code += 2; } if ($code) { return $code; } if (preg_match('/\bballoon\b/i', $string)) { return 1; } return 0; } $sentences = [ 'Here is a green, blue, and red balloon', 'A blue balloon here', 'A red herring', 'Blue is the name of my dog', 'Red and green are Xmas colors', 'blue skies over green grass', 'Foo is bar', 'Have a balloon and a balloon and a balloon', 'A green balloon', 'A blue balloon with a red string', ]; foreach ($sentences as $sentence) { printf("%s => %d\n", $sentence, getCode($sentence)); }
Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.28, 8.4.1 - 8.4.14, 8.4.16, 8.5.0 - 8.5.1
Here is a green, blue, and red balloon => 11 A blue balloon here => 3 A red herring => 2 Blue is the name of my dog => 3 Red and green are Xmas colors => 6 blue skies over green grass => 7 Foo is bar => 0 Have a balloon and a balloon and a balloon => 1 A green balloon => 4 A blue balloon with a red string => 5
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.

preferences:
155.97 ms | 407 KiB | 5 Q