您可以对文件进行编码,例如使用htmlentities。
例如,使用这个小代码,我将瑞典文件编码为 ISO-8859-1,
$file = fopen("translations-sv.csv", "r");
$new_file = fopen("file_encoded.csv", "w");
while(!feof($file)) {
$line=fgets($file);
$line = str_replace(";", ",",$line); //replace all ';' to ','
$encoded_line=htmlentities($line,ENT_QUOTES,'ISO-8859-1');
fwrite($new_file, $encoded_line);
}
fclose($file);
fclose($new_file);
瑞典语.csv
title_orders;Beställningar
title_monthly_sales;Månadsförsäljning
title_settings;Inställningar
file_encoded.csv
title_orders,Beställningar
title_monthly_sales,Månadsförsäljning
title_settings,Inställningar
并且,比较,
$new_file = fopen("file_encoded.csv", "r");
$word_to_find="Orderslutförande";
while (!feof($new_file) ) {
$line_of_text = fgetcsv($new_file, 1024,",");
if($word_to_find==$line_of_text[1])
echo $line_of_text[1]." is the same to $word_to_find<br>";
}
fclose($new_file);