PHP UTF-16 to ASCII conversion

点点圈 提交于 2019-12-12 05:27:08

问题


Consider the following string. Its encoded in UTF-16-LE and saved into a PHP variable. I failed to get either mbstring or iconv to replace the ' with single quote. What would be a good way to sanatize it.

String : Carl Sagan's Cosmic Connection


回答1:


Unless I'm misunderstanding the question, ' isn't a UTF-16 issue. That string has had htmlspecialchars() or htmlentities() run on it, and the single quote was converted to the html entity represenation '.

To get it back to normal you need to do an html_entity_decode().

Generally you only want to do html encoding at output time so you avoid persisting that kind of conversion. If you are taking in HTML input somewhere to get these kind of strings, you probably want to decode entities before you do the UTF conversion and storage.



来源:https://stackoverflow.com/questions/1196838/php-utf-16-to-ascii-conversion

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!