PHP convert foreign characters with accents

后端 未结 5 1289
有刺的猬
有刺的猬 2020-12-16 08:03

Hi I\'m trying to compare some text to the text in a database.. in the database any text with an accent is encoded like in html (ie. é) when I compare the databas

5条回答
  •  -上瘾入骨i
    2020-12-16 08:25

    You need to send in the correct charset to htmlentities. It looks like you're using UTF-8, but the default is ISO-8859-1. Change it like this:

    $encoded = htmlentities($text, ENT_COMPAT, 'UTF-8');
    

    Another solution is to convert the text to ISO-8859-1 before encoding, but that may destroy information (ISO-8859-1 does not contain nearly as many characters as UTF-8). If you want to try that instead, do like this:

    $encoded = htmlentities(utf8_decode($text));
    

提交回复
热议问题