3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php const VLANS = [ 'default' => [ 'prefix' => '', ], 'iutsb_rech' => [ 'prefix' => '129.20.', ], 'iutsb_etu' => [ 'prefix' => '148.60.', ] ]; const SHORT_VLANS = [ 'e' => 'iutsb_etu', 'r' => 'iutsb_rech', ]; function a($hostname) { $vlanShort = substr($hostname, 1, 1); if (!array_key_exists($vlanShort, self::SHORT_VLANS)) { return false; } $prefix = self::VLANS[self::SHORT_VLANS[$vlanShort]]['prefix']; $prefixLength = substr_count($prefix, '.'); $hostnameLength = strlen($hostname); $ip = []; for ($i = $prefixLength; $i < 4; $i++) { $ip[] = intval(substr($hostname, $hostnameLength + (($i - 4) * 3), 3)); } return $prefix . implode('.', $ip); } echo a('me212128');
Output for 7.0.0
Fatal error: Cannot use "self" when no class scope is active in /in/8GUqF on line 21
Process exited with code 255.
Output for 5.6.8 - 5.6.16
Fatal error: Cannot access self:: when no class scope is active in /in/8GUqF on line 21
Process exited with code 255.
Output for 5.4.10 - 5.5.30
Fatal error: Arrays are not allowed as constants in /in/8GUqF on line 12
Process exited with code 255.
Output for 5.3.20 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/8GUqF on line 2
Process exited with code 255.