西班牙语字符无法正确显示 [英] Spanish Characters not Displaying Correctly

查看:244
本文介绍了西班牙语字符无法正确显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了一个可爱的 框,其中应显示西班牙语字符. (即:ñ,á等).我已经确保将我的meta http-equiv设置为utf-8:

I am getting the lovely � box where spanish characters should be displayed. (ie: ñ, á, etc). I have already made sure that my meta http-equiv is set to utf-8:

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

我还确保还为utf-8设置了页眉:

I have also made sure that the page header is set for utf-8 also:

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

这是到目前为止我的代码的开始阶段:

Here is the beginning stages of my code thus far:

<?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> 

上面的代码在where语句中.我读过切换数据库中的排序规则也可能是一个因素,但是我已经将其设置为UTF-8 General ci.另外,该列中唯一的内容还是DateTime,它是数字,无论如何都无法整理.

The above code is in a where statement. I have read that switching the collation in the database can also be a factor but I already have it set to UTF-8 General ci. Plus, the only thing that is in that column is DateTime anyway which is numbers and cannot be collated anyway.

结果:萨巴多8:00

result: s�bado 8:00

任何帮助一如既往.

推荐答案

PHP/MySQL/UTF-8需要考虑的事情

Things to consider in PHP/MySQL/UTF-8

  • 数据库表和文本列应设置为UTF-8
  • HTML页面的Content-Type应该设置为UTF-8

  • The database tables and text columns should be set to UTF-8
  • HTML page Content-Type should be set to UTF-8

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

PHP应该发送一个标头,通知浏览器使用UTF-8

PHP should send a header informing the browser to expect UTF-8

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

PHP-MySQL连接应设置为UTF-8

The PHP-MySQL connection should be set to 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');

PHP ini has default_charset setting it should be utf-8 if you do not have access to it use ini_set('default_charset', 'utf-8');

这篇关于西班牙语字符无法正确显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆