我遇到一些 Mysql 字符错误。
<?php
$con = mysql_connect("localhost", "root", "");
if(!$con){
die(mysql_error());
echo "Não foi possivel ligar-se à base de dados";
}
$select_db = mysql_select_db("desempenho", $con);
if(!$select_db){
die(mysql_error());
echo "Não foi possivel selecionar a base de dados";
}
mysql_query("SET NAMES 'utf8'");
?>
现在这是包含此内容的另一个页面:
include "../includes/connect.php";
session_start();
$nome = $_SESSION['nome'];
事情还在继续。
$nome 变量通过 session 传递并从登录中获取。当该变量的名称如“João”时,由于“ã”,我在打印该变量时遇到错误。 (该变量存储登录时获取的用户名)
我还有 html 标签来识别 UTF-8 字符
<meta http-equiv='Content-type' value='text/html; charset=UTF-8' />
这是错误: HTML 包含无效的 UTF-8 字符
提前致谢
最佳答案
I also have the html tag to recognize UTF-8 Caracters
这个 HTML 标签完全没用。这是 HTTP header 设置编码,而不是 HTML 标记。
header('Content-Type: text/html; charset=utf-8');
关于php - Mysql utf8字符错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23135901/