Spanish characters do not display correctly

I get a beautiful box in which Spanish characters should be displayed. (i.e.: ñ, á, etc.). I have already verified that my meta http-equiv is set to utf-8:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

I also made sure the page title is also set for utf-8:

header('Content-type: text/html; charset=UTF-8');

Here are the initial steps of my code:

<?php
    setlocale(LC_ALL, 'es_MX');
    $datetime = strtotime($event['datetime']);
    $date = date("M j, Y", $datetime);
    $day = strftime("%A", $datetime);
    $time = date("g:i", $datetime);
?>
    <a href="/<?= $event['request'] ?>.html"><?= $day ?> <?= $time ?></a> 

The above code is in the where statement. I read that including sorting in the database can also be a factor, but I already installed it in UTF-8 General ci. In addition, the only thing in this column is DateTime in any case, which is a number and cannot be matched in any case.

result: s bado 8:00

Any help is much appreciated, as always.

+5
source share
5 answers

PHP/MySQL/UTF-8

  • UTF-8
  • HTML- Content-Type ​​ UTF-8

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

  • PHP , , UTF-8

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

  • PHP-MySQL UTF-8

    mysqli_query("SET CHARACTER_SET_CLIENT='utf8'",$conn);

    mysqli_query("SET CHARACTER_SET_RESULTS='utf8'",$conn);

    mysqli_query("SET CHARACTER_SET_CONNECTION='utf8'",$conn);

  • PHP ini default_charset, utf-8 , ini_set('default_charset', 'utf-8');

+6

, , .

html- . , , .

function span_accent($wordz)
{

$wordz = str_replace( "Á","&Aacute;",$wordz);
$wordz = str_replace( "É","&Eacute;",$wordz);
$wordz = str_replace( "Í","&Iacute;",$wordz);
$wordz = str_replace( "Ó","&Oacute;",$wordz);
$wordz = str_replace( "Ú","&Uacute;",$wordz);
$wordz = str_replace( "Ñ","&Ntilde;",$wordz);
$wordz = str_replace( "Ü","&Uuml;",$wordz);

$wordz = str_replace( "á","&aacute;",$wordz);
$wordz = str_replace( "é","&eacute;",$wordz);
$wordz = str_replace( "í","&iacute;",$wordz);
$wordz = str_replace( "ó","&oacute;",$wordz);
$wordz = str_replace( "ú","&uacute;",$wordz);
$wordz = str_replace( "ñ","&ntilde;",$wordz);
$wordz = str_replace( "ü","&uuml;",$wordz);

$wordz = str_replace( "¿","&iquest;",$wordz);
$wordz = str_replace( "¡","&iexcl;",$wordz);
$wordz = str_replace( "€","&euro;",$wordz);
$wordz = str_replace( "«","&laquo;",$wordz);
$wordz = str_replace( "»","&raquo;",$wordz);
$wordz = str_replace( "‹","&lsaquo;",$wordz);
$wordz = str_replace( "›","&rsaquo;",$wordz);
return $wordz;
}
+4

ENCODING. UTF-8 UTF-8 .

. Notepad ++ ( , ). > ENCODING > UTF-8 UTF-8 .

. UTF-8 UTF-8 . UTF-8 UTF-8 ?

, .:)

+2

, UTF-8 ( ).

( ), , ISO-8859-1 ISO-8859-15.

0

You can see that the content is correct in the database table, look at it with phpmyadmin, for example. If so, make sure your php files are encoded in utf8, look at the ide / editor configuration.

0
source

All Articles