Filipe Oliveira 0 Posted July 2, 2019 Report Share Posted July 2, 2019 (edited) Boas, Estou a fazer um site de noticias Gaming onde recolho dados da base de dados e listo em Html. O problema: Defini o agrupamento da base de dados como utf8_general_ci mas quando listo os registos os acentos não aparecem aparece algo como �����. Como podem ver no inicio do código utilizei header('Content-Type: text/html; charset=utf-8'); que foi o que vi num fórum inglês mas como não percebo muito de inglês não percebi o que tinha que por mais no código para que funcionasse corretamente. Se alguém me pode-se ajudar agradecia. <?PhP header('Content-Type: text/html; charset=utf-8'); if(!isset($_GET["ordenar"])) { $ordenar="titulo"; } else { $ordenar=$_GET["ordenar"]; } if($ordenar=='referencia') { $ordenar_por="order by referencia"; } if($ordenar=='titulo') { $ordenar_por="order by titulo"; } if($ordenar=='nomejogo') { $ordenar_por="order by nomejogo"; } if($ordenar=='dataregisto') { $ordenar_por="order by dataregisto DESC"; } include("LigaBD.php"); $lista="SELECT * FROM noticias WHERE publicado!=0 $ordenar_por"; $faz_lista=mysqli_query($ligaBD, $lista); $num_registos=mysqli_num_rows($faz_lista); if($num_registos==0) { echo "<script>alert('Nao existem noticias para listar!');</script>"; exit('<script>location.href = "ADMINISTRADOR.php"</script>'); } function limita_caracteres($texto, $limite, $quebra = true){ //Codigo para delimitar texto tirado de uma base de dados $tamanho = strlen($texto); if($tamanho <= $limite){ //Verifica se o tamanho do texto é menor ou igual ao limite $novo_texto = $texto; }else{ // Se o tamanho do texto for maior que o limite if($quebra == true){ // Verifica a opção de quebrar o texto $novo_texto = trim(substr($texto, 0, $limite))."..."; }else{ // Se não, corta $texto na última palavra antes do limite $ultimo_espaco = strrpos(substr($texto, 0, $limite), " "); // Localiza o útlimo espaço antes de $limite $novo_texto = trim(substr($texto, 0, $ultimo_espaco))."..."; // Corta o $texto até a posição localizada } } return $novo_texto; // Retorna o valor formatado } ?> <html> <head> <meta charset="UTF-8"> <style type="text/css"> img { float: center; margin: 5px; width: 120px; height: 80px; } tr th{ padding: 5px 25px; } td{ padding: 0px 8px; max-width: 350px; text-align: center; } </style> </head> <body bgcolor="#C0C0C0"> <!--cor de fundo da pagina--> <table border="1" align="center" bgColor=white bordercolor=#0d0d0d> <tr><th Colspan=11 bgColor=white bordercolor=#0d0d0d>Noticias Publicadas: <?php echo "$num_registos"; ?> <!--Cabecalho da tabela--> <tr> <tr bgColor=white bordercolor=#0d0d0d> <th><a href="ListarNoticiasPublicadas.php?ordenar=referencia">Referencia da noticia</a></th> <th><a href="ListarNoticiasPublicadas.php?ordenar=titulo">Titulo da noticia</a></th> <th>Descricao da noticia</th> <th><a href="ListarNoticiasPublicadas.php?ordenar=nomejogo">Nome do jogo</a></th> <th>Imagem da noticia</th> <th><a href="ListarNoticiasPublicadas.php?ordenar=dataregisto">Data de registo</a></th> <th>Ocultar</th> <th>Editar</th> <th>Eliminar</th> </tr> <?php for ($i=0; $i<$num_registos; $i++) { $registos = mysqli_fetch_array($faz_lista); echo'<tr>'; echo'<td>'.$registos['referencia'].'</td>'; echo limita_caracteres('<td>'.$registos['titulo'].'</td>', 80); echo limita_caracteres('<td>'.$registos['descricao'].'</td>',300); echo'<td>'.$registos['nomejogo'].'</td>'; echo'<td>'."<img src='Imagens/".$registos['imagem']."'>".'</td>'; echo'<td>'.$registos['dataregisto'].'</td>'; echo'<td><a href="OcultarNoticia.php?referencia='.$registos['referencia'].'">Ocultar noticia</a></td>'; echo'<td><a href="EditarNoticiaPublicada.php?referencia='.$registos['referencia'].'">Editar noticia</a></td>'; echo'<td><a href="EliminarNoticiaPublicada.php?referencia='.$registos['referencia'].'">Eliminar noticia</a></td>'; } echo"<br>"; ?> </table> </body> </html> <center> <br> <table width="1000px" border="0" cellspacing="30px" cellpadding="4"> <tr align="center"> <td><a href="ADMINISTRADOR.php"><button style="width:180px;height:50px">Voltar</button></a></td> </tr> </table> </center> Edited July 3, 2019 by Filipe Oliveira Resolvido Link to post Share on other sites
SDFK 0 Posted July 2, 2019 Report Share Posted July 2, 2019 Amigo, usaste o header('Content-Type: text/html; charset=utf-8'); Na última tag <?php. Link to post Share on other sites
Filipe Oliveira 0 Posted July 2, 2019 Author Report Share Posted July 2, 2019 5 horas atrás, SDFK disse: Amigo, usaste o header('Content-Type: text/html; charset=utf-8'); Na última tag <?php. Desculpa, não entendi podes explicar melhor? Link to post Share on other sites
SDFK 0 Posted July 4, 2019 Report Share Posted July 4, 2019 Em 02/07/2019 às 22:56, Filipe Oliveira disse: Desculpa, não entendi podes explicar melhor? Usaste o código header('Content-Type: text/html; charset=utf-8');, inicio da ultima tag <?php do teu código? Link to post Share on other sites
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now