dtt27783 2017-05-18 17:26
浏览 67

为什么在回显变量时,替换字符会不断出现?

I'm creating a test application and keeping the name of the person who is taking it on a table, along with the answers. The problem lies when I enter the following characters

á é í ó ú ñ

I've tried some methods (like iconv function) but still not working.

//A sample of the code

require('../connect_db.php');
setlocale(LC_ALL,"es_ES");
mysql_query("SET NAMES 'utf8'");

$sql  =  "SELECT *
          FROM database.test";
$result     = mysql_query($sql) or die (mysql_error());
$row        = mysql_fetch_array($result);
$name      = utf8decode($row[1]);

echo mb_detect_encoding($name); //Just to test
echo $name;

The result:

UTF-8 G�mez


Edit: The problem is not on the database. I've manually entered names with these characters with no problem, so it must be the code.

  • 写回答

1条回答 默认 最新

  • doufu6196 2017-05-18 19:13
    关注

    SOLVED

    There was no need to run the first utf8decode() when assigning values to $name

    Instead I just called the function at the echo

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度