php - 带有日文字符的 substr 问题

标签 php utf-8 character-encoding

我很好地回显了日文字符,但是当我尝试 substr 并回显部分字符串时,它只是变成了问号 ����

注意:我将标题设置为 utf-8

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

并制作了元数据 <meta http-equiv="Content-type" content="text/html; charset=utf-8" />

$word = "せんせい";
echo $word;       //works just fine

echo substr($word,-1);    //now it just echoes �

//this one also failed
echo $word[0];    //echoes �

最佳答案

使用多字节字符串时,您需要使用 multibyte string函数,在本例中为 mb_substr .

关于php - 带有日文字符的 substr 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11737890/

相关文章:

php - 使用数据库触发器生成无间隙数字

mysql - 在 Latin 1 --> UTF-8 中是否存在我需要修复的隐藏编码错误?

android - 如何比较android中的文本UTF-8?

c# - 从 C# 在 PHP 中解密的字符编码问题

perl - 在 Perl 中,看到 é 是 e,E 的变体

character-encoding - 更改响应头编码 .Net Core

c++ - '\u0B95' 是多字 rune 字吗?

php - 如何在 CodeIgniter 迁移中使用 down() 方法?

php - 结帐页面上的返 repo 物车按钮

php - 如何在数据库中创建表