PHP CSV Reader/Writer
What is a simple way to read/write CSV files with PHP?
I wonder if its possible to read strings containing chars like in
Lil' Bucket™ Chocolate Crème Parfait Cup from a CSV file and also output the same string when writting to a new CSV file.
The problem I'm having is that the above string prints out like this:
Lil' Bucket™ Lemon Crème Parfait Cup
...which makes开发者_运维百科 it hard to read for a user.
fputscsv()
and fgetcsv()
Read from csv file
$content=fopen('file.csv','r');
while(!feof($content)){
$abin[]=fgetcsv($content);
}
echo "<pre>";
print_r($abin);
Create new csv file
$list=array(
array('abin','savin','sherin','tomy','linish'),
array('111','222','333'),
array('aaa','bbb','ccc','ddd')
);
$fp=fopen('file.csv','w');
foreach($list as $lists)
{
fputcsv($fp,$lists);
}
fclose($fp);
精彩评论