<?php | |
/** | |
* Converts UTF-8 to XML-safe HTML entities: Изложение => Изложение | |
*/ | |
function xmlencode($string) { | |
$string = (string) $string; | |
// Replace < and ' and & etc. | |
$string = htmlspecialchars($string, ENT_XML1 | ENT_QUOTES); | |
// Replace ë etc. | |
$string = preg_replace_callback('#[\x{0080}-\x{00ff}]#u', function($match) { | |
return '&#' . ord(utf8_decode($match[0])) . ';'; | |
}, $string); | |
// Replace Russian etc. | |
$string = mb_convert_encoding($string, 'HTML-ENTITIES'); | |
return $string; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment