3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Sample generation $sampleUTF8 = 'Here is some lovely Russian: На берегу пустынных волн Стоял он, дум великих полн, И вдаль глядел. Пред ним широко Река неслася; бедный чёлн По ней стремился одиноко. and something else: ԠѬΏݑޤ'; $sampleUTF16 = mb_convert_encoding($sampleUTF8, 'UTF-16', 'UTF-8'); /** * Detect Encoding * Attempts to identify the encoding of the subject string; returns the encoding as a string. * * @param string $subject * * @return string * @throws \RuntimeException Encoding could not be identified */ function detect(string $subject): string { if (mb_detect_encoding($subject, 'auto')) { return mb_detect_encoding($subject, 'ASCII, UTF-8, UTF-7, UTF-16, UTF-16BE, UTF-16LE, UTF-32, UTF-32BE, UTF-32LE, SJIS, JIS, ISO-8859-1, ISO-8859-2, ISO-8859-3, ISO-8859-4, ISO-8859-5, ISO-8859-6, ISO-8859-7, ISO-8859-8, ISO-8859-9, ISO-8859-10, ISO-8859-11, ISO-8859-12, ISO-8859-13, ISO-8859-14, ISO-8859-15, Windows-1251, Windows-1252, Windows-1254, BASE-64, UCS-2, UCS-2BE, UCS-2LE, UCS-4, UCS-4BE, UCS-4LE, CP51932, CP50222, CP50221, CP50220, CP950, CP936, CP932, CP866, CP850, auto', true); } else { throw new \RuntimeException('Could not identify the string\'s encoding.'); } } echo detect($sampleUTF16);
Output for git.master, git.master_jit
Fatal error: Uncaught RuntimeException: Could not identify the string's encoding. in /in/OZqmh:22 Stack trace: #0 /in/OZqmh(28): detect('\x00H\x00e\x00r\x00e\x00 \x00i\x00s\x00...') #1 {main} thrown in /in/OZqmh on line 22
Process exited with code 255.
Output for rfc.property-hooks
Fatal error: Uncaught ValueError: mb_detect_encoding(): Argument #2 ($encodings) contains invalid encoding "ISO-8859-11" in /in/OZqmh:20 Stack trace: #0 /in/OZqmh(20): mb_detect_encoding('\x00H\x00e\x00r\x00e\x00 \x00i\x00s\x00...', 'ASCII, UTF-8, U...', true) #1 /in/OZqmh(28): detect('\x00H\x00e\x00r\x00e\x00 \x00i\x00s\x00...') #2 {main} thrown in /in/OZqmh on line 20
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
60.38 ms | 1678 KiB | 4 Q