首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用处理国家名称的.txt文件时,字符编码会丢失

使用处理国家名称的.txt文件时,字符编码会丢失
EN

Stack Overflow用户
提问于 2011-07-11 23:31:06
回答 2查看 332关注 0票数 1

我正在处理ISO-3166中的国家名称文本文件,以便将国家名称提取到一个数组中。问题是,当我输出数组时,某些国家/地区的特殊字符丢失或更改:

代码语言:javascript
复制
$country_1 = fopen("./country_names_iso_3166.txt", "r");        
while( !feof($country_1) ) {  // go through every line of file
$country = fgets( $country_1 );
if( strstr($country, ",") )         // if country name contains a comma
    $i = strpos( $country, "," ); // index position of comma
else
    $i = strpos( $country, ";" );   // index position of semicolon
$country = substr( $country, 0, $i );   // extract just the country name
$countries[] = $country;
}

因此,现在当我输出数组时,例如,第二个国家名称应该是奥兰岛,但它输出为陆地岛……请建议如何解决此问题。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-07-11 23:52:49

请尝试使用支持多字节的字符串函数。mb_strstr()、mb_strpos()、mb_substr() (基本上只是前缀mb_)。

票数 1
EN

Stack Overflow用户

发布于 2011-07-11 23:34:07

确保输出数据的流使用与输入文件相同的字符集。

(删除了说ISO-3166是字符集的错误)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6652597

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档