php with special characters like ñ

喜你入骨 提交于 2019-12-03 03:31:35

for me

$test = "Nuñez";
echo $test;

shows Nuñez

You may try

$test = "Nuñez";
echo utf8_decode($test);

or

$test = utf8_encode("Nuñez");
echo utf8_decode($test);

Try this

Its works for me.

$test = "Nuñez";

echo html_entity_decode(htmlentities($test));

to show correctly latin characters like ñ Ñ á é í ó ú, etc.. in browsers, you have to use iso-8859-1 instead of UTF-8 encoding http://www.w3schools.com/tags/ref_entities.asp

best regards!

when you connect to your mysql db, set charset to utf-8, like ->

$sql_con = mysql_connect($sql_host, $sql_user, $sql_pass);
mysql_query('SET NAMES utf8');

consider setting default_charset, this worked for me

ini_set('default_charset', 'utf-8');

itassets

Face the same issue with the string "CASTAÑO".

I've tried posted solutions.

I used the ini_set('default_charset', 'utf-8'); directive.

  • The selected record showed "CASTA�O"
  • Using utf8-decode showed "CASTA?O"
  • Using utf8_encode shows the proper string "CASTAÑO"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!