口音和 UTf-8 php 使用 strtolower
accents and UTf-8 php using strtolower
我读了一个带有 simpleXlsx 解析器插件的 XLSX。
我的 excel 的第一行是 header,我需要阅读它。
在我的 excel 中,例如第一行有 3 列名称为 header:
Columns_1 Columns_with_accent_à Columns_3
第二列有重音符号:à
我的编辑器处于 UTF-8 模式,我的 php 页面设置了 UTF-8 编码,我没有在我的页面上使用任何 html(是否仅在php) 但我得到了这个 var 转储:
<?php
header('Content-type: text/html; charset=UTF-8');
$xlsx = SimpleXLSX::parse("file.xlsx");
foreach( $xlsx->rows() as $indexrow => $r ) {
if ( $indexrow == 0 ) {
// HEADER
var_dump(strtolower($r[1])); //second column
//output WRONG: Columns_with_accent_�
}
}
?>
知道 strtolower 破坏了我的弦吗?没有它,效果很好
查看评论和编辑(未在 the original post) about the use of strtolower()
中显示,手册指出:
Note that 'alphabetic' is determined by the current locale. This means that e.g. in the default "C" locale, characters such as umlaut-A (Ä) will not be converted.
另一方面,mb_strtolower() 显示:
By contrast to strtolower(), 'alphabetic' is determined by the Unicode character properties. Thus the behaviour of this function is not affected by locale settings and it can convert any characters that have 'alphabetic' property, such as A-umlaut (Ä).
我读了一个带有 simpleXlsx 解析器插件的 XLSX。
我的 excel 的第一行是 header,我需要阅读它。
在我的 excel 中,例如第一行有 3 列名称为 header:
Columns_1 Columns_with_accent_à Columns_3
第二列有重音符号:à
我的编辑器处于 UTF-8 模式,我的 php 页面设置了 UTF-8 编码,我没有在我的页面上使用任何 html(是否仅在php) 但我得到了这个 var 转储:
<?php
header('Content-type: text/html; charset=UTF-8');
$xlsx = SimpleXLSX::parse("file.xlsx");
foreach( $xlsx->rows() as $indexrow => $r ) {
if ( $indexrow == 0 ) {
// HEADER
var_dump(strtolower($r[1])); //second column
//output WRONG: Columns_with_accent_�
}
}
?>
知道 strtolower 破坏了我的弦吗?没有它,效果很好
查看评论和编辑(未在 the original post) about the use of strtolower()
中显示,手册指出:
另一方面,Note that 'alphabetic' is determined by the current locale. This means that e.g. in the default "C" locale, characters such as umlaut-A (Ä) will not be converted.
mb_strtolower() 显示:
By contrast to strtolower(), 'alphabetic' is determined by the Unicode character properties. Thus the behaviour of this function is not affected by locale settings and it can convert any characters that have 'alphabetic' property, such as A-umlaut (Ä).