具有特殊字符的echo字符串无法正确显示

时间:2014-04-28 14:30:18

标签: php

正确的字符串是CultoMensalÁreaVilaMariana,但它似乎是Culto Mensal rea Vila Mariana .... Gratidão=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>";
    }
    ?>

2 个答案:

答案 0 :(得分:3)

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

使用:

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

<meta charset="UTF-8">

head标记内的html中。

另外,作为旁注:

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

请查看PDOmysqli_*

答案 1 :(得分:1)

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

您需要在:

中设置UTF8
  • 数据库结构(列整理)
  • 数据库连接(很多人忘了这个)
  • 页面本身(如{BeatAlex答案中的charset=utf-8
必须正确设置

ALL THREE