<?php
$str = "don't-break-me-überÆØÅ!";
print htmlspecialchars_decode($str, ENT_QUOTES) . PHP_EOL;
print html_entity_decode($str, ENT_QUOTES) . PHP_EOL;
print html_entity_decode($str, ENT_QUOTES, 'ISO-8859-1') . PHP_EOL;
print html_entity_decode($str, ENT_QUOTES | ENT_XML1, 'ISO-8859-1') . PHP_EOL;
print html_entity_decode($str, ENT_QUOTES, 'UTF-8') . PHP_EOL;
// Decode ALL entities (double quotes ("),
// single quotes (' + ') and non printable chars (e.g. ))
print html_entity_decode($str, ENT_QUOTES | ENT_XML1, 'UTF-8') . PHP_EOL;
// Convert &#[0-9]+ entities to UTF-8
$new = preg_replace_callback("/(&#[0-9]+;)/", function($m) {
return mb_convert_encoding($m[1], "UTF-8", "HTML-ENTITIES");
}, $str);
print $new . PHP_EOL;
// Convert &#[0-9]+ entities to ISO-8859-1
$new2 = preg_replace_callback("/(&#[0-9]+;)/", function($m) {
return mb_convert_encoding($m[1], "ISO-8859-1", "HTML-ENTITIES");
}, $str);
print $new2 . PHP_EOL;
preferences:
54.76 ms | 402 KiB | 5 Q