PHP — PHP 5.4.6, pasted 5 years ago (json)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <?php
function xml_entities($string) {
return strtr(
$string,
array(
"<" => "<",
">" => ">",
'"' => """,
"'" => "'",
"&" => "&",
)
);
}
$text = "Test & <b> and encode </b> :)";
echo xml_entities($text);
|
Test &amp; <b> and encode </b> :)
OK (0.004 sec real, 0.005 sec wall, 13 MB, 42 syscalls)