我正在尝试从POST表单中获取数据.当用户输入“habláis”时,它在视图源中显示为“habláis”.我想将其转换为“habl& aacute; is”以进行字符串比较,但utf8_encode()和htmlentities()都输出habl& Atilde;& iexcl;是,而htmlspecialchars()什么都不做.我会使用str_replace但它在搜索字符串时不会识别á.
我在页面上一直使用utf-8的字符集.知道发生了什么事吗?
解决方法:
我不确定这是不是你的问题,但是你用UTF-8参数调用htmlentities吗?我问,因为那不是它的默认值:
Like htmlspecialchars(), it takes an
optional third argument charset which
defines character set used in
conversion. Presently, the ISO-8859-1
character set is used as the default.
所以你可能想尝试这样调用你的函数:
$output = htmlentities($input, ENT_COMPAT, 'UTF-8');
这会解决您的问题吗?
标签:html,php,utf-8
来源: https://codeday.me/bug/20190730/1577813.html