[PHP-users 21541]Re: 内部エンコードUTF8のファイルからUTF-16のCSVファイルを読み込む
aiko
vvv_aiko_vvv @ hotmail.com
2004年 5月 6日 (木) 04:01:39 JST
$B$*@$OC$K$J$C$F$*$j$^$9!#(B
$B4_ @ n$G$9!#(B
$B0JA0!"(BUTF-8$B$G(BUTF-16$B$N(BCSV$B%U%!%$%k$rFI$_9~$`J}K!$G<ALd$5$;$F$$$?$@$-$^$7$?!#(B
$B>.;3MM$K%"%I%P%$%9$r85$K!"%W%m%0%i%`$r5-=R$7$F$_$^$7$?$,!"(B
$B0lItJ8;z2=$1$7$F$7$^$$>e<j$/$$$-$^$;$s!#(B
$BF|K\8l!"(BASCII$B$N$_$HN>J};n$7$F$_$^$7$?$,!"$I$A$i$b2=$1$F$7$^$$$^$9!#(B
$B>.;3MM$N4D6-$G$OI=<($G$-$?MM$G$9$,!D(B
$B$I$NMM$J860x$,9M$($i$l$k$G$7$g$&$+!#(B
$B2?EY$b62=L$G$9$,!"$4=u8@$h$m$7$/$*4j$$$7$^$9!#(B
//// test.php(UTF-8) /////
/* $B0J2<$N%=!<%9$r<B9T$9$k$H!"(Baaa.txt$B$N(B1$B9TL\$,2=$1$k(B */
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>$B%F%9%H(B</title>
</head>
<body>
<?php
// $B%U%!%$%k$+$iFI$_9~$_5-=R(B
testRead($data);
for ( $i=0; $i<count($data); $i++ ) {
print "[$i] " ;
for ( $j=0; $j<count($data[$i]); $j++ ) {
print $data[$i][$j] ;
}
print "<br>";
print "<br>";
}
?>
</body>
</html>
<?php
// UTF16$BMQ(B
function testRead( &$data )
{
// $B%U%!%$%kL>(B
$fn="./aaa.txt";
$row=0;
// file $B$r%*!<%W%s$7$F(B
$fp = fopen($fn, 'r');
while (!feof($fp)) {
// 1$B9TFI$_9~$_(B
$line = fgets($fp);
// $BJ8;z%3!<%I$rJQ49$7$F(B
$line = mb_convert_encoding($line, 'UTF-8', 'UTF-16');
// $B<+J,$G(B , $B$G6h @ Z$k(B
$data[$row] = explode(',', $line);
$row++;
}
fclose($fp);
return ;
}
?>
//// aaa.txt(UTF-16) /////
TEST1-1,TEST1-2,TEST1-3
TEST2-1,TEST2-2,TEST2-3
TEST3-1,TEST3-2,TEST3-3
//// aaa.txt(UTF-16) $B%P%$%J%j(B /////
54,00,45,00,53,00,54,00,31,00,2D,00,31,00,2C,00,
54,00,45,00,53,00,54,00,31,00,2D,00,32,00,2C,00,
54,00,45,00,53,00,54,00,31,00,2D,00,33,00,0A,00,
54,00,45,00,53,00,54,00,32,00,2D,00,31,00,2C,00,
54,00,45,00,53,00,54,00,32,00,2D,00,32,00,2C,00,
54,00,45,00,53,00,54,00,32,00,2D,00,33,00,0A,00,
54,00,45,00,53,00,54,00,33,00,2D,00,31,00,2C,00,
54,00,45,00,53,00,54,00,33,00,2D,00,32,00,2C,00,
54,00,45,00,53,00,54,00,33,00,2D,00,33,00,0A,00,
// $BI=<(7k2L(B( $B9T?t$O$-$A$s$HG'<1$7$F$$$k(B )
[0] ??$ByM(B???????$ByM(B???????$ByM(B???? // $B"+$3$3$,2=$1$F$$$k!#(B
[1] TEST2-1TEST2-2TEST2-3
[2] TEST3-1TEST3-2TEST3-3
[3]
_________________________________________________________________
$B%a%C%;%s%8%c!<$GAm3[(B1$B2/1_%W%l%<%s%H!*(B http://im.msn.co.jp/home.htm
PHP-users メーリングリストの案内