带有特殊字符的echo字符串;t显示正确


echo string with special chars doesn't appear correctly

正确的字符串是Culto MensalÁrea Vila Mariana,但它显示为Culto MensalÁrea Vila Mariana。。。。Gratidão=

我已经尝试过使用htmlspecialchars功能

<?php
    include "mysqlconecta.php"; // Conecta ao banco de dados
    $result=mysql_query("select * from CDEventos");
    echo "<table width=900 border='"2'">";
    echo "<tr>";
    echo "<td>Titulo</td>";
    echo "<td>Local</td>";
    echo "<td>Data</td>";
    while($row=mysql_fetch_array($result)){
    echo "<tr>";
    echo "<td>".$row['titulo']."</td>";
    echo "<td>".$row['local']."</td>";
    echo "<td>".$row['data']."</td>";
    echo "<td>";
    echo "<a href='"altera.php?id=".$row['id']."'">Alterar</a>"; 
    echo  "&nbsp&nbsp";
    echo "<a href='"deletar.php?id=".$row['id']."'">Excluir</a>";
    echo "</td>";
    echo "</tr>";
    }
    ?>

您需要将内容设置为UTF-8

使用任一:

header('Content-Type: text/html; charset=utf-8');

在PHP或中

<meta charset="UTF-8">

在CCD_ 2标签内的html中。

此外,作为旁注:

请不要继续使用mysql_*函数,因为它们已被弃用。

请查看PDOmysqli_*

您的字符串在UTF8中,因此必须将其作为UTF8处理。

您需要在中设置UTF8

  • 数据库结构(列排序规则)
  • 数据库连接(很多人忘记了这一点)
  • 页面本身(如BeatAlexs的回答中的charset=utf-8

必须正确设置所有三个