用php 读CSV文件 :用户名,今天日志,今天在线,本周在线,今日主题,总发帖,总主题,精华帖,总日志,总积分,总在线/小时,本月在线
zql,,115,215,,343,122,1,22,1241,83,2425
hyf359709555,,65,110,,28,1,0,0,108,9,360
sophie,,0,0,,0,0,0,0,2,0,0
cbn,,,,,0,0,0,0,0,0,
罗布布,,10,10,,100,14,1,5,618,18,360
LingShame,,0,70,,22,1,0,1,133,6,270
MOOD,,50,100,,5,1,0,6,146,19,840
六岁就很酷,,0,0,,8,0,0,0,109,5,20
李伟, ,35,195,,92,31,5,1,421,17,875
可是我读出来
用的中文有一些有问题.
/小时
zql 115 215 343 122 1 22 1241 83 2425
so肥 15 50 14 50 0 75 5 60
0 0 0 0 2 0 0
cbn 0 0 0 0 0 0 10 10
100 14 1 5 618 18 360
LingShame 0 70 22 1 0 1 133 6 270
50 100 5 1 0 6 146 19 840
0 0 8 0 0 0 109
5 20 35 195中文不好好显示,我用的是Apache2.2 Php 5.3.6
在线等解决。
zql,,115,215,,343,122,1,22,1241,83,2425
hyf359709555,,65,110,,28,1,0,0,108,9,360
sophie,,0,0,,0,0,0,0,2,0,0
cbn,,,,,0,0,0,0,0,0,
罗布布,,10,10,,100,14,1,5,618,18,360
LingShame,,0,70,,22,1,0,1,133,6,270
MOOD,,50,100,,5,1,0,6,146,19,840
六岁就很酷,,0,0,,8,0,0,0,109,5,20
李伟, ,35,195,,92,31,5,1,421,17,875
可是我读出来
用的中文有一些有问题.
/小时
zql 115 215 343 122 1 22 1241 83 2425
so肥 15 50 14 50 0 75 5 60
0 0 0 0 2 0 0
cbn 0 0 0 0 0 0 10 10
100 14 1 5 618 18 360
LingShame 0 70 22 1 0 1 133 6 270
50 100 5 1 0 6 146 19 840
0 0 8 0 0 0 109
5 20 35 195中文不好好显示,我用的是Apache2.2 Php 5.3.6
在线等解决。
error_reporting(E_ALL & ~(E_STRICT | E_NOTICE));
$link_id = mysql_connect("localhost","root","k1k2") or die("连接失败");
mysql_query("set names 'gbk'");
if($link_id)
{
mysql_select_db("ht_data");
$member="select username,blognum,thisday,thisweek,num,posts,threads,digestposts,blogs,credits,oltime,thismonth from hpre_common_member as mumberTemp
left JOIN hpre_common_member_count as countTemp ON mumberTemp.uid = countTemp.uid
left JOIN hpre_common_member_profile as profileTemp ON countTemp.uid = profileTemp.uid
left JOIN hpre_common_onlinetime as onlinetimeTemp ON countTemp.uid = onlinetimeTemp.uid
left JOIN (select author,authorid ,COUNT(author) as num
from hpre_forum_thread
where date_format(NOW(),'%Y-%m-%d')=FROM_UNIXTIME(dateline,'%Y-%m-%d')
GROUP BY author) as childTemp
on childTemp.authorid=countTemp.uid
left join (
select username as log_username,uid ,COUNT(username) as blognum
from hpre_home_blog
where date_format(NOW(),'%Y-%m-%d')=FROM_UNIXTIME(dateline,'%Y-%m-%d')
GROUP BY username
)as logTemp
on logTemp.uid=mumberTemp.uid";
$result=mysql_query($member);
$query=mysql_fetch_array($result);
$name=date("Y-m-d");
$fp = fopen($name.'.csv', 'w'); while($row=mysql_fetch_array($result)){
$thred[]=$row;
} $con= array("用户名","今天日志","今天在线","本周在线","今日主题","总发帖","总主题","精华帖","总日志","总积分","总在线/小时","本月在线");
}
fputcsv($fp,$con);
for($j=0;$j<count($thred);$j++){
for($i=0;$i<count($thred[$j]);$i++){
array_splice($thred[$j],$i,1);
}
}
foreach($thred as $r){
fputcsv($fp,$r);
}
fclose($fp);
?>
{
$ROW = 1;
while($date = fgetcsv($handle_Pram,15000,","))
{
$num = count($date);
$ROW ++;
for($c =0;$c<$num;$c++)
{
echo $date[$c];
}echo "<br>";
}
}
$handle = fopen("2011-06-24.csv","r");
Print_Test($handle);
fclose($$handle);
就是用fgetcsv读的
setlocale(LC_ALL, 'en_US.UTF-8');
// 简体
setlocale(LC_ALL, 'zh_CN');
据说CSV不支持UTF-8
(听说)