PHP 是否有任何标准函数来将 Unicode 字符串转换为普通的、良好的老式 ANSI 字符串(或 PHP 的 htmlentities
理解的任何格式?
是否有任何函数可以将 UTF-8 字符串转换为最流行的浏览器可以理解的 HTML?
最佳答案
这不能正常工作。用 Unicode 存储的字符比用 ANSI 存储的字符多得多。 因此,如果您“转换”为 ANSI,就会丢失很多字符。
http://php.net/manual/en/function.htmlentities.php
您可以将 Unicode (UTF-8) 字符集与 htmlentities 一起使用:
string htmlentities ( string $string [, int $flags = ENT_COMPAT [, string $charset [, bool $double_encode = true ]]] )
htmlentities($myString, ENT_COMPAT, "UTF-8");
应该可以工作。
关于PHP:将 Unicode 字符串转换为 ANSI 字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4691477/