我很好地回显了日文字符,但是当我尝试 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/