3v4l.org

run code in 300+ PHP versions simultaneously
<?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.5.24 - 5.5.30
Fatal error: Arrays are not allowed as constants in /in/8GUqF on line 12
Process exited with code 255.

preferences:
182.47 ms | 1395 KiB | 24 Q