开发者

PHP CSV Reader/Writer

开发者 https://www.devze.com 2023-04-12 06:08 出处:网络
What is a simple way to read/write CSV files with PHP? I wonder if its possible to read strings containing chars like in

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号