php utf8 html字符,PHP:utf-8编码,htmlentities给出了奇怪的结果
我正在嘗試從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
總結
以上是生活随笔為你收集整理的php utf8 html字符,PHP:utf-8编码,htmlentities给出了奇怪的结果的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 分布式锁 哨兵模式_手撕redis分布式
- 下一篇: php设计者,PHP设计者---comp