PHP で作成したヘブライ語のテキストを含む CSV ファイルをインポートしたいと考えています。
これは私がファイルを作成した方法です:
header("Content-Type: application/comma-separated-values; charset=UTF-16LE");
header("Content-Disposition: attachment; filename=\"$fileName\"");
res = "";
foreach($data as $row) {
foreach($row as $coll) {
$res .= $coll . "\t";
}
$res .= "\r\n";
}
// Convert $res from UTF8 to UTF-16LE and add special chars at the beginning
echo chr(255) . chr(254) . mb_convert_encoding($res, 'UTF-16LE', 'UTF-8');
そのコードは機能し、ヘブライ文字が正しく表示された CSV ファイルを取得します。
同じファイルを読み取ろうとすると、ヘブライ文字がうまく表示されません (たとえば、ÔÒàÔ âÜ ÔÒÕã 0)。これは私が試したコードです:
$fp = fopen($file_full_path,'r') or die("can't open file");
print "<table>\n";
while($csv_line = fgetcsv($fp)) {
print '<tr>';
for ($i = 0, $j = count($csv_line); $i < $j; $i++)
{
$val = $csv_line[$i];
print '<td>'.$val.'</td>';
}
print "</tr>\n";
}
print '</table>\n';
fclose($fp) or die("can't close file");
このソリューションは、英語、ヘブライ語、フランス語、ドイツ語などの文字で機能するはずです。