Skip to content

Instantly share code, notes, and snippets.

@heiglandreas
Last active April 9, 2022 20:30
Show Gist options
  • Save heiglandreas/cffb73a0f7d6f05bb6a6e831f2892c24 to your computer and use it in GitHub Desktop.
Save heiglandreas/cffb73a0f7d6f05bb6a6e831f2892c24 to your computer and use it in GitHub Desktop.
PHP DOM oddities
<?php
declare(strict_types=1);
$string = <<<'EOF'
Bar
<meta content="text/html; charset=unicode" http-equiv="Content-Type">
Foo
EOF;
libxml_use_internal_errors(true);
$dom = new DOMDocument('1.0', 'UTF-8');
$dom->loadHTML('<?xml encoding="UTF-8">'.$string);
echo $dom->saveHTML();
print_R(get_loaded_extensions());
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<?xml encoding="UTF-8"><html><body><p>Bar
<meta content="text/html; charset=unicode" http-equiv="Content-Type">&#2622;&dagger;&#17952;&#28527;</p></body></html>
Array
(
[0] => Core
[1] => date
[2] => libxml
[3] => openssl
[4] => pcre
[5] => sqlite3
[6] => zlib
[7] => ctype
[8] => curl
[9] => dom
[10] => fileinfo
[11] => filter
[12] => ftp
[13] => hash
[14] => iconv
[15] => json
[16] => mbstring
[17] => SPL
[18] => session
[19] => PDO
[20] => pdo_sqlite
[21] => standard
[22] => posix
[23] => readline
[24] => Reflection
[25] => Phar
[26] => SimpleXML
[27] => tokenizer
[28] => xml
[29] => xmlreader
[30] => xmlwriter
[31] => mysqlnd
[32] => intl
[33] => ldap
[34] => sodium
[35] => zip
[36] => Zend OPcache
[37] => xdebug
)
https://3v4l.org/KiqAO
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<?xml encoding="UTF-8"><html><body><p>Bar
<meta content="text/html; charset=unicode" http-equiv="Content-Type"></p></body></html>
Array
(
[0] => Core
[1] => date
[2] => libxml
[3] => pcre
[4] => sqlite3
[5] => zlib
[6] => ctype
[7] => dom
[8] => fileinfo
[9] => filter
[10] => hash
[11] => json
[12] => mbstring
[13] => SPL
[14] => PDO
[15] => session
[16] => posix
[17] => Reflection
[18] => standard
[19] => SimpleXML
[20] => pdo_sqlite
[21] => Phar
[22] => tokenizer
[23] => xml
[24] => xmlreader
[25] => xmlwriter
[26] => gmp
[27] => iconv
[28] => intl
[29] => bcmath
[30] => sodium
[31] => Zend OPcache
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment