3v4l.org

run code in 300+ PHP versions simultaneously
<?php ini_set("error_reporting", -1 & ~E_DEPRECATED); set_error_handler(function($s, $m, $f, $l, $c = null) { print "PHP Warning: $m in " . basename($f) . " on line $l"; }, E_WARNING); $xml = base64_decode("PGRpdj48cD7M4OzgIOz76+Ag8ODs8y48L3A+PC9kaXY+"); $options = LIBXML_HTML_NOIMPLIED | LIBXML_NOENT | LIBXML_NONET | LIBXML_NOWARNING | LIBXML_NOXMLDECL | LIBXML_HTML_NODEFDTD ; print "<pre>"; foreach([ 'default_charset', 'input_encoding', 'internal_encoding', 'output_encoding', 'iconv.input_encoding', 'iconv.internal_encoding', 'iconv.output_encoding', 'mbstring.http_input', 'mbstring.http_output', 'mbstring.internal_encoding', ] as $set) { ini_set($set, "UTF-8"); printf("%-12s: %s\n", $set, ini_get($set)); } print "</pre>"; ob_start(function($str, $phase) { return iconv("Windows-1251", "UTF-8", $str); }); print "--- CP1251 ---\n$xml\n"; print "Direct:"; $doc = new DOMDocument; $doc->loadHTML("$xml", $options); $doc->encoding = "Windows-1251"; print $doc->saveXML(null, LIBXML_NOENT); print "With encoding:"; $doc = new DOMDocument("1.0", "Windows-1251"); $doc->loadHTML("$xml", $options); $doc->encoding = "Windows-1251"; print $doc->saveXML(null, LIBXML_NOENT); print "With inline encoding:"; $doc = new DOMDocument; $doc->loadHTML("<?xml version=\"1.0\" encoding=\"Windows-1251\" standalone=\"yes\"?>$xml", $options); $doc->encoding = "Windows-1251"; print $doc->saveXML(null, LIBXML_NOENT); print "With both:"; $doc = new DOMDocument("1.0", "Windows-1251"); $doc->loadHTML("<?xml version=\"1.0\" encoding=\"Windows-1251\" standalone=\"yes\"?>$xml", $options); $doc->encoding = "Windows-1251"; print $doc->saveXML(null, LIBXML_NOENT); ob_end_flush(); $xml = iconv("Windows-1251", "UTF-8", $xml); print "--- UTF-8 ---\n$xml\n"; print "Direct:\n"; $doc = new DOMDocument; $doc->loadHTML("$xml", $options); $doc->encoding = "UTF-8"; print $doc->saveXML(null, LIBXML_NOENT); print "With encoding:\n"; $doc = new DOMDocument("1.0", "UTF-8"); $doc->loadHTML("$xml", $options); $doc->encoding = "UTF-8"; print $doc->saveXML(null, LIBXML_NOENT); print "With inline encoding:"; $doc = new DOMDocument; $doc->loadHTML("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>$xml", $options); $doc->encoding = "UTF-8"; print $doc->saveXML(null, LIBXML_NOENT); print "With both:"; $doc = new DOMDocument("1.0", "UTF-8"); $doc->loadHTML("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>$xml", $options); $doc->encoding = "UTF-8"; print $doc->saveXML(null, LIBXML_NOENT);
Output for 8.0.14 - 8.0.26, 8.1.0 - 8.1.13
<pre>default_charset: UTF-8 input_encoding: UTF-8 internal_encoding: UTF-8 output_encoding: UTF-8 iconv.input_encoding: UTF-8 iconv.internal_encoding: UTF-8 iconv.output_encoding: UTF-8 mbstring.http_input: UTF-8 mbstring.http_output: UTF-8 mbstring.internal_encoding: UTF-8 </pre>--- CP1251 --- <div><p>���� ��� ����.</p></div> Direct:<?xml version="1.0" encoding="Windows-1251" standalone="yes"?> <div><p>&#224;&#224; &#251;&#224; &#224;&#243;.</p></div> With encoding:<?xml version="1.0" encoding="Windows-1251" standalone="yes"?> <div><p>&#224;&#224; &#251;&#224; &#224;&#243;.</p></div> With inline encoding:PHP Warning: DOMDocument::loadHTML(): Input is not proper UTF-8, indicate encoding ! in Entity, line: 1 in HL5It on line 56PHP Warning: DOMDocument::saveXML(): output conversion failed due to conv error, bytes 0x00 0x3F 0x78 0x6D in HL5It on line 58<?xml version="1.0" encoding="Windows-1251" standalone="yes"?> <?xml version="1.0" encoding="Windows-1251" standalone="yes"??> <div><p>With both:PHP Warning: DOMDocument::loadHTML(): encoder errorInput is not proper UTF-8, indicate encoding ! in Entity, line: 1 in HL5It on line 62PHP Warning: DOMDocument::saveXML(): output conversion failed due to conv error, bytes 0x00 0x3F 0x78 0x6D in HL5It on line 64<?xml version="1.0" encoding="Windows-1251" standalone="yes"?> <?xml version="1.0" encoding="Windows-1251" standalone="yes"??> <div><p>PHP Warning: iconv(): Wrong encoding, conversion from "Windows-1251" to "UTF-8" is not allowed in HL5It on line 37PHP Warning: iconv(): Wrong encoding, conversion from "Windows-1251" to "UTF-8" is not allowed in HL5It on line 68--- UTF-8 --- Direct: Fatal error: Uncaught ValueError: DOMDocument::loadHTML(): Argument #1 ($source) must not be empty in /in/HL5It:73 Stack trace: #0 /in/HL5It(73): DOMDocument->loadHTML('', 10310) #1 {main} thrown in /in/HL5It on line 73
Process exited with code 255.
Output for 7.3.32 - 7.3.33, 7.4.33, 8.0.13
<pre>default_charset: UTF-8 input_encoding: UTF-8 internal_encoding: UTF-8 output_encoding: UTF-8 iconv.input_encoding: iconv.internal_encoding: iconv.output_encoding: mbstring.http_input: UTF-8 mbstring.http_output: UTF-8 mbstring.internal_encoding: UTF-8 </pre>--- CP1251 --- <div><p>���� ��� ����.</p></div> Direct:<?xml version="1.0" encoding="Windows-1251" standalone="yes"?> <div><p>&#224;&#224; &#251;&#224; &#224;&#243;.</p></div> With encoding:<?xml version="1.0" encoding="Windows-1251" standalone="yes"?> <div><p>&#224;&#224; &#251;&#224; &#224;&#243;.</p></div> With inline encoding:PHP Warning: DOMDocument::loadHTML(): Input is not proper UTF-8, indicate encoding ! in Entity, line: 1 in HL5It on line 56PHP Warning: DOMDocument::saveXML(): output conversion failed due to conv error, bytes 0x00 0x3F 0x78 0x6D in HL5It on line 58<?xml version="1.0" encoding="Windows-1251" standalone="yes"?> <?xml version="1.0" encoding="Windows-1251" standalone="yes"??> <div><p>With both:PHP Warning: DOMDocument::loadHTML(): encoder errorInput is not proper UTF-8, indicate encoding ! in Entity, line: 1 in HL5It on line 62PHP Warning: DOMDocument::saveXML(): output conversion failed due to conv error, bytes 0x00 0x3F 0x78 0x6D in HL5It on line 64<?xml version="1.0" encoding="Windows-1251" standalone="yes"?> <?xml version="1.0" encoding="Windows-1251" standalone="yes"??> <div><p> Fatal error: Uncaught Error: Call to undefined function iconv() in /in/HL5It:37 Stack trace: #0 [internal function]: {closure}('--- CP1251 ---\n...', 9) #1 /in/HL5It(66): ob_end_flush() #2 {main} thrown in /in/HL5It on line 37
Process exited with code 255.
Output for 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.25, 8.0.0 - 8.0.12
<pre>default_charset: UTF-8 input_encoding: UTF-8 internal_encoding: UTF-8 output_encoding: UTF-8 iconv.input_encoding: UTF-8 iconv.internal_encoding: UTF-8 iconv.output_encoding: UTF-8 mbstring.http_input: UTF-8 mbstring.http_output: UTF-8 mbstring.internal_encoding: UTF-8 </pre>--- CP1251 --- <div><p>Мама мыла раму.</p></div> Direct:<?xml version="1.0" encoding="Windows-1251" standalone="yes"?> <div><p>&#204;&#224;&#236;&#224; &#236;&#251;&#235;&#224; &#240;&#224;&#236;&#243;.</p></div> With encoding:<?xml version="1.0" encoding="Windows-1251" standalone="yes"?> <div><p>&#204;&#224;&#236;&#224; &#236;&#251;&#235;&#224; &#240;&#224;&#236;&#243;.</p></div> With inline encoding:PHP Warning: DOMDocument::loadHTML(): Input is not proper UTF-8, indicate encoding ! in Entity, line: 1 in HL5It on line 56PHP Warning: DOMDocument::saveXML(): output conversion failed due to conv error, bytes 0xCC 0xC3 0xA0 0xC3 in HL5It on line 58<?xml version="1.0" encoding="Windows-1251" standalone="yes"?> <?xml version="1.0" encoding="Windows-1251" standalone="yes"??> <div><p>With both:PHP Warning: DOMDocument::loadHTML(): encoder errorInput is not proper UTF-8, indicate encoding ! in Entity, line: 1 in HL5It on line 62PHP Warning: DOMDocument::saveXML(): output conversion failed due to conv error, bytes 0xCC 0xC3 0xA0 0xC3 in HL5It on line 64<?xml version="1.0" encoding="Windows-1251" standalone="yes"?> <?xml version="1.0" encoding="Windows-1251" standalone="yes"??> <div><p>--- UTF-8 --- <div><p>Мама мыла раму.</p></div> Direct: <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <div><p>Мама мыла раму.</p></div> With encoding: <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <div><p>Мама мыла раму.</p></div> With inline encoding:<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <?xml version="1.0" encoding="UTF-8" standalone="yes"??> <div><p>Мама мыла раму.</p></div> With both:<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <?xml version="1.0" encoding="UTF-8" standalone="yes"??> <div><p>Мама мыла раму.</p></div>
Output for 7.4.26 - 7.4.32
<pre>default_charset: UTF-8 input_encoding: UTF-8 internal_encoding: UTF-8 output_encoding: UTF-8 iconv.input_encoding: UTF-8 iconv.internal_encoding: UTF-8 iconv.output_encoding: UTF-8 mbstring.http_input: UTF-8 mbstring.http_output: UTF-8 mbstring.internal_encoding: UTF-8 </pre>--- CP1251 --- <div><p>���� ��� ����.</p></div> Direct:<?xml version="1.0" encoding="Windows-1251" standalone="yes"?> <div><p>&#224;&#224; &#251;&#224; &#224;&#243;.</p></div> With encoding:<?xml version="1.0" encoding="Windows-1251" standalone="yes"?> <div><p>&#224;&#224; &#251;&#224; &#224;&#243;.</p></div> With inline encoding:PHP Warning: DOMDocument::loadHTML(): Input is not proper UTF-8, indicate encoding ! in Entity, line: 1 in HL5It on line 56PHP Warning: DOMDocument::saveXML(): output conversion failed due to conv error, bytes 0x00 0x3F 0x78 0x6D in HL5It on line 58<?xml version="1.0" encoding="Windows-1251" standalone="yes"?> <?xml version="1.0" encoding="Windows-1251" standalone="yes"??> <div><p>With both:PHP Warning: DOMDocument::loadHTML(): encoder errorInput is not proper UTF-8, indicate encoding ! in Entity, line: 1 in HL5It on line 62PHP Warning: DOMDocument::saveXML(): output conversion failed due to conv error, bytes 0x00 0x3F 0x78 0x6D in HL5It on line 64<?xml version="1.0" encoding="Windows-1251" standalone="yes"?> <?xml version="1.0" encoding="Windows-1251" standalone="yes"??> <div><p> Notice: iconv(): Wrong charset, conversion from `Windows-1251' to `UTF-8' is not allowed in /in/HL5It on line 37 Notice: iconv(): Wrong charset, conversion from `Windows-1251' to `UTF-8' is not allowed in /in/HL5It on line 68 --- UTF-8 --- Direct: PHP Warning: DOMDocument::loadHTML(): Empty string supplied as input in HL5It on line 73<?xml version="1.0" encoding="UTF-8"?> With encoding: PHP Warning: DOMDocument::loadHTML(): Empty string supplied as input in HL5It on line 79<?xml version="1.0" encoding="UTF-8"?> With inline encoding:<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <?xml version="1.0" encoding="UTF-8" standalone="yes"??> With both:<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <?xml version="1.0" encoding="UTF-8" standalone="yes"??>

preferences:
78.12 ms | 429 KiB | 5 Q