3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Set internal encoding to ISO-8859-9 and assign string an initial value of Turkish characters $t = mb_internal_encoding('ISO-8859-9'); echo "Internal Encoding set? ".$t."\n"; $s = 'ııİöÖğĞçÇşŞ'; $t = mb_internal_encoding(); echo "Internal Encoding: ".$t."\n"; // Check if the string is valid UTF-8 $t = mb_check_encoding($s, 'UTF-8'); echo "Valid UTF-8? ".$t."\n"; // Check if the string is valid ISO-8859-1 $t = mb_check_encoding($s, 'ISO-8859-9'); echo "Valid ISO-8859-9? ".$t."\n"; //Convert string from ISO-8859-9 to ISO-8859-9 while internal encoding is ISO-8859-9 $e = mb_convert_encoding($s, 'ISO-8859-9', 'ISO-8859-9'); echo "Convert string to ISO-8859-9 from ISO-8859-9 while internal encoding ISO-8859-9: ".$e."\n"; //Convert string from ISO-8859-9 to ISO-8859-9 while internal encoding is ISO-8859-9 $i = mb_convert_encoding($s, 'ISO-8859-9'); echo "Convert string to ISO-8859-9 with no source supplied: ".$e."\n"; //Convert string to UTF-8 - if using the detected encoding it will fail $e = mb_convert_encoding($i, 'UTF-8', 'ISO-8859-9'); echo "*** Convert string to UTF-8 from ISO-8859-9: ".$e."\n"; //Display the encoding options available for detection $t = mb_detect_order(); echo "Detect Order: ".print_r($t)."\n"; //Detect encoding of string without influencing the encoding options $t = mb_detect_encoding($s); echo "Encoding detected? ".$t."\n"; //Set a preferred order of matching for detection $t = mb_detect_order('ASCII,UTF-8,ISO-8859-9,ISO-8859-15'); echo "Detect Order set? ".$t."\n"; //Display the encoding options available for detection $t = mb_detect_order(); echo "Detect Order: ".print_r($t)."\n"; //Detect encoding of string after setting the preferred order of detection $t = mb_detect_encoding($s); echo "Encoding detected? ".$t."\n"; //Set internal encoding to UTF-8 $t = mb_internal_encoding('UTF-8'); echo "Internal Encoding set? ".$t."\n"; //Convert string from ISO-8859-9 to ISO-8859-9 while internal encoding is UTF-8 $e = mb_convert_encoding($s, 'ISO-8859-9', 'ISO-8859-9'); echo "Convert string ISO-8859-9 from ISO-8859-9 while internal encoding is UTF-8: ".$e."\n"; //Detect encoding of string $t = mb_detect_encoding($s); echo "Encoding detected? ".$t."\n"; //Convert string to UTF-8 - if using the detected encoding it will fail $e = mb_convert_encoding($s, 'UTF-8', $t); echo "*** Convert string to UTF-8 using Detected Encoding $t as source encoding: ".$e."\n"; //Convert string to UTF-8 - using no source encoding works $e = mb_convert_encoding($s, 'UTF-8'); echo "*** Convert string to UTF-8 without supplying a source encoding: ".$e."\n"; //Convert string to UTF-8 - if using UTF-8 as source $e = mb_convert_encoding($s, 'UTF-8', 'UTF-8'); echo "*** Convert string to UTF-8 using UTF-8 as source encoding: ".$e."\n"; //Even though string is initialised and detected as ISO-8859-9 - it seems it is being treated //internally as though it is actually UTF-8. //Converting to ISO-8859-9 from UTF-8 works - with some characters undisplayable $e = mb_convert_encoding($s, 'ISO-8859-9', 'UTF-8'); echo "Convert string to ISO-8859-9 from UTF-8: ".$e."\n"; //Converting to this string back to UTF-8 from ISO-8859-9 works $e = mb_convert_encoding($e, 'UTF-8', 'ISO-8859-9'); echo "Convert resultant string to UTF-8 from ISO-8859-9: ".$e."\n"; //Converting to this string back to UTF-8 from UTF-8 works $e = mb_convert_encoding($e, 'UTF-8', 'UTF-8'); echo "Convert resultant string to UTF-8 from UTF-8: ".$e."\n";

preferences:
128.54 ms | 410 KiB | 5 Q