Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Olá galera estou terminando de fazer um site mas só falta resolver um problema, fiz o seguinte sistema de notícias, simples...
e quando coloco o include para puxar o arquivo noticias.php para a pagina index.php os caracteres com acentos ficam assim: � (um ponto de interrogação) mas o mais estranho é que quando acesso a pagina noticias.php em link direto os caracteres aparecem normalmente!
no banco de dados os caracteres são "utf8_unicode_ci" e na pagina index.php está "<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />"
Enviar.php (responsavel por inserir a notícia no DB)
<?
include 'config_not.php';
$titulo = $_POST['titulo'];
$noticia = $_POST['mensagem'];
$gm = $_POST['gm'];
$data = $_POST['data'];
if($noticia == null){
echo '<h1>Preencha o campo mensagem!!</h1>';
exit();
}
if($gm == null){
echo '<h1>Preencha o campo GM!!</h1>';
exit();
}
if($data == null){
echo '<h1>Preencha o campo data!!</h1>';
exit();
}
$inserir = mysql_query("insert into noticias (titulo, noticia, por, data) values ('$titulo', '$noticia', '$gm', '$data')");
if($inserir > 0){
echo 'mensagem enviada com sucesso!!!<br/>';
echo '<a href="index.php">Voltar para o site</a>';echo 'mensagem não enviada com sucesso!!!<br/>';
echo '<a href="index.php">Voltar para o site</a>';
}
?>
Inserir.php (formulario para criar notícia)
<? include 'config_not.php'; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="[http://www.w3.org/1999/xhtml">](http://www.w3.org/1999/xhtml)
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>inserir</title>
<style type="text/css">.style1 {
font-family: "Courier New", Courier, monospace;
color: #666666;
}
.style3 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #FF0000;
}
.style4 {
font-family: Georgia, "Times New Roman", Times, serif;
font-size: 18px;
color: #333333;
}
.style5 {
font-family: Arial, Helvetica, sans-serif;
font-size: 9px;
color: #999999;
}</style>
</head>
<body>
<form name="form" method="post" action="enviar.php">
<p class="style4">Sistema de notícias RagnaPremium</p>
<table width="768" height="156" border="0">
<tr>
<td><span class="style1">Título:</span></td>
<td><input type="text" name="titulo" />
<span class="style1">( 10.10.10 - Nova notícia)</span></td>
<td class="style3">Colocar o título</td>
</tr>
<tr>
<td width="127"><span class="style1">Notícia:</span> </td>
<td width="500"><textarea name="mensagem" cols="60" rows="10"></textarea></td>
<td width="127" class="style3">Colocar o título seguido da notícia.</td>
</tr>
<tr>
<td class="style1">Escrito por: </td>
<td><input type="text" name="gm" />
<span class="style1">( ADM Teste)</span></td>
<td><span class="style3">Seu cargo (GM, ADM...) e seu nick.</span></td>
</tr>
<tr>
<td class="style1">Data:</td>
<td><input type="text" name="data" />
<span class="style1">( 10.10.10 )</span> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><input type="submit" value="Enviar Notícia" /></td>
<td> </td>
</tr>
</table></form>
<p> </p>
</body>
</html>
Noticias.php (exibe a notícia no site)
<? include 'config_not.php' ?>
<?
$sql = 'select * from noticias order by id desc limit 5';
$executar = mysql_query($sql);
while ($exibir = mysql_fetch_array($executar)){
echo '<table width="500" border="0">
<tr>
<td width="417" class="titulonoti">'.$exibir['titulo'].'</td>
<td width="73"><div align="center" class="vermais">VER +</div></td>
</tr>
</table>Obrigado.
>
Substitua esta linha:
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />Um abraço.
Olá Willian,
não funcionou...
estou usando uma função em JS que abre uma pagina dentro de uma div...
e fiz um teste em relação a isso puxei a pagina notícia fora da div mostrar_conteudo e os caracteres funcionaram normalmente mas quando carrego dentro da o erro... o código js é o seguinte:
ajax.js
// <![CDATA[
function fixOutOfMemoryError() {
__flash_unloadHandler = function() {};
__flash_savedUnloadHandler = function() {};
}
window.attachEvent("onbeforeunload", fixOutOfMemoryError);function abre(arquivo){
var xmlHttp;
try {
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e) {
// Internet Explorer
try {
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e){
try {
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {
alert("Seu navegador não suporta AJAX. Atualize-o em www.getfirefox.com");
return false;
}
}
}
xmlHttp.onreadystatechange=function() {
if(xmlHttp.readyState == 1) {
document.getElementById("coluna_meio").innerHTML = ("<div id=\"carregando\"><img src=\"imagens/loader.gif\" width=\"16\" height=\"16\" border=\"0\"> Carregando... Aguarde!</div>");
}
if(xmlHttp.readyState == 4) {
document.getElementById("coluna_meio").innerHTML = xmlHttp.responseText;
}
}
xmlHttp.open("GET",arquivo,true);
xmlHttp.send(null);
}
e na pagina ta assim:
<body onLoad="abre('inicial.php');)" >
Obrigado.
você pode tentar codificar os caracteres vindo do banco de dados
<td width="417" class="titulonoti">'.utf8_decode($exibir['titulo']).'</td>
@Willian,
Piorou, agora nem se eu acessar diretamente pelo link 127.0.0.1/rp/noticias.php os caracteres funcionam.
@jpraminelli
não fez efeito, mas vlw aprendi um comando novo =D
mas o problema continua.
Abraços.
entao tente o contrario
<td width="417" class="titulonoti">'.utf8_encode($exibir['titulo']).'</td>
jpraminelli,
funcionou, muito obrigado!!
fico grato, abraço.
RESOLVIDO
Substitua esta linha: