3v4l.org

run code in 300+ PHP versions simultaneously
<?php $charset = 'UTF-8'; // PHP Meh. $encoding = 'UTF-8'; header('Content-Type: application/xml; charset=' . $charset); ini_set('default_charset', $charset); mb_internal_encoding('UTF-8'); $rawUtf8Text = '豁ヲ蠢・'; $encodedText = mb_encode_numericentity($rawUtf8Text, [0x0, 0xffff, 0, 0xffff], 'UTF-8'); $clearText = mb_decode_numericentity($encodedText, [0x0, 0xffff, 0, 0xffff], 'UTF-8'); echo "RAW UTF-8 STRING: {$clearText}\nNUMERICALLY ENCODED STRING: {$encodedText}\nROUND TRIP ENCODE/DECODE STRING: {$clearText}\n"; $xml = '<first-name>' . $encodedText . '</first-name>'; echo "ENCODED XML TO BE PARSED:{$xml}\n"; $decodedFromXml = mb_decode_numericentity(strip_tags($encodedText), [0x0, 0xffff, 0, 0xffff], 'UTF-8'); echo "DECODED STRING FROM XML: {$decodedFromXml}\n";
Output for 5.6.38, 7.0.0 - 7.0.32, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
RAW UTF-8 STRING: 豁ヲ蠢・ NUMERICALLY ENCODED STRING: &#35905;&#65382;&#34850;&#12539; ROUND TRIP ENCODE/DECODE STRING: 豁ヲ蠢・ ENCODED XML TO BE PARSED:<first-name>&#35905;&#65382;&#34850;&#12539;</first-name> DECODED STRING FROM XML: 豁ヲ蠢・
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 RAW UTF-8 STRING: 豁ヲ蠢・ NUMERICALLY ENCODED STRING: &#35905;&#65382;&#34850;&#12539; ROUND TRIP ENCODE/DECODE STRING: 豁ヲ蠢・ ENCODED XML TO BE PARSED:<first-name>&#35905;&#65382;&#34850;&#12539;</first-name> DECODED STRING FROM XML: 豁ヲ蠢・

preferences:
219.22 ms | 402 KiB | 244 Q