<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body><p>Bar
<meta content="text/html; charset=unicode" http-equiv="Content-Type">ਾ†䘠潯</p></body></html>
ਾ†䘠潯
ਾ†䘠潯
��>
Foo
Created
April 11, 2022 07:55
-
-
Save heiglandreas/86c7ccfaceb0ccf355a03c01326fae4c to your computer and use it in GitHub Desktop.
Never use "unicode" as Content-Type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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(); | |
$dom->loadHTML($string); | |
$f = $dom->saveHTML(); | |
echo $f . PHP_EOL . PHP_EOL; | |
$weirdStuff = preg_match('/>([\&\#a-zA-Z0-9\;]+)</', $f, $result); | |
echo $result[1] . PHP_EOL . PHP_EOL; | |
$utf8 = mb_convert_encoding($result[1], 'UTF-8', 'HTML-ENTITIES'); | |
echo $utf8 . PHP_EOL . PHP_EOL; | |
echo iconv('UTF-8', 'unicode', $utf8) . PHP_EOL . PHP_EOL; |
// Check out https://3v4l.org/kJ0tV
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body><p>Bar
<meta content="text/html; charset=unicode" http-equiv="Content-Type">㸊†⁆潯</p></body></html>
㸊†⁆潯
㸊†⁆潯
Warning: iconv(): Wrong encoding, conversion from "UTF-8" to "unicode" is not allowed in /in/kJ0tV on line 22
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment