问题
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