php将字符串写入csv文件中

时间:2016-08-05
php的fputcsv()函数用于将数据格式为csv格式,以便写入文件或者数据库,本文章向大家介绍php如何使用fputcsv()将字符串写入到csv文件中,需要的朋友可以参考一下。

fputcsv() 函数用于将数据格式为csv格式,以便写入文件或者数据库。

下面代码演示了如何使用fputcsv()函数将字符串写入csv文件中:

$test_array = array(
        array("php","java","css","mysql","xml"),
        array("html","javascript","js","apache","json"),
        array("csv","file","sql","css3","bootstrap"),
        array("jquery","editor","thinkphp","ci","html")
    );
    /* http://www.manongjc.com/article/1311.html */
    $file = fopen("test.csv","w") or die("Can't Open test.csv");
    foreach($test_array as $line_array)
    {
        $isSuccess = fputcsv($file,$line_array);
        print $isSuccess."<br>";     if($isSuccess===false)
        {
            die("Can't write csv line".$line_array);
        }
    }
    fclose($file) or die("Can't close file test.csv.");

上一页 下一页

原文地址:http://www.manongjc.com/article/1311.html