1

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

$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;
}

所以现在当我输出数组时,例如,第二个国家名称应该是 ÅLAND ISLANDS,但是它输出为 LAND ISLANDS...请告知如何解决这个问题。

4

2 回答 2

1

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

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

于 2011-07-11T15:34:06.543 回答
1

尝试改用多字节感知字符串函数。mb_strstr(), mb_strpos(), mb_substr() (基本上只是前缀mb_)。

于 2011-07-11T15:52:48.580 回答