3v4l.org

run code in 300+ PHP versions simultaneously
<?php function charset_decode_utf_8 ($string) { /* Only do the slow convert if there are 8-bit characters */ /* avoid using 0xA0 (\240) in ereg ranges. RH73 does not like that */ if (! ereg("[\200-\237]", $string) and ! ereg("[\241-\377]", $string)) return $string; // decode three byte unicode characters $string = preg_replace("/([\340-\357])([\200-\277])([\200-\277])/e", \ "'&#'.((ord('\\1')-224)*4096 + (ord('\\2')-128)*64 + (ord('\\3')-128)).';'", \ $string); // decode two byte unicode characters $string = preg_replace("/([\300-\337])([\200-\277])/e", \ "'&#'.((ord('\\1')-192)*64+(ord('\\2')-128)).';'", \ $string); return $string; } $str = "Vanliga fr\u00e5gor"; $decoded_str = charset_decode_utf_8($str); print $decoded_str;
Output for 5.4.0 - 5.4.29
Parse error: syntax error, unexpected '"'&#'.((ord('\\1')-224)*4096 +' (T_CONSTANT_ENCAPSED_STRING), expecting identifier (T_STRING) in /in/NvFX0 on line 11
Process exited with code 255.
Output for 5.3.0 - 5.3.28
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting T_STRING in /in/NvFX0 on line 11
Process exited with code 255.

preferences:
204.81 ms | 1395 KiB | 66 Q