我使用以下代码:
$wpCharset = "UTF8" //or any other charset
//http://php.net/manual/en/domdocument.loadhtml.php#74777
$content = mb_convert_encoding($content, 'HTML-ENTITIES', $wpCharset);
$dom = new DOMDocument('1.0', $wpCharset);
$success = $dom->loadHtml('<!DOCTYPE html><html><meta http-equiv="Content-Type" content="text/html; charset=' . $wpCharset . '" /><body>' . $content);问题是,有些用户没有在服务器上安装有效的"mbstring“扩展。在这种情况下,有没有mb_convert_encoding的替代方案?
非常感谢
发布于 2015-09-01 14:10:44
只需使用$content = htmlentities($content)即可
它与UTF-8兼容。要查看所有兼容性,请查看php.net:http://us3.php.net/manual/en/function.htmlentities.php
这只是替换了字符串中的双引号,这对于XML来说是可以的。如果要将单引号转义为,请使用$content = htmlentitites($content,ENT_QUOTES)
https://stackoverflow.com/questions/32322406
复制相似问题