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";

preferences:
64.72 ms | 409 KiB | 5 Q