0

我厌倦了使用fgetcsv函数解析 Google CSV 文件..

这是我的代码:

<?php 

    $fp = fopen("google12.csv", 'r');

    $fileHeader = array();
    $firstRow = array();
    $index = 0;
    while (($data = fgetcsv($fp)) !== FALSE && $index != 2)
    {
        if ($index == 0)
            $fileHeader = $data;
        elseif ($index == 1)
            $firstRow = $data;

        $index++;
    }

    fclose($fp);

    $parameter = array("header" => $fileHeader,"firstRow" => $firstRow);

    echo json_encode($parameter);
    exit;

?>

样本格式错误的 CSV 包含

"Name,Given Name,Additional Name,Family Name,Yomi Name,Given Name Yomi,Additional Name Yomi,Family Name Yomi,Name Prefix,Name Suffix,Initials,Nickname,Short Name,Maiden Name,Birthday,Gender,Location,Billing Information,Directory Server,Mileage,Occupation,Hobby,Sensitivity,Priority,Subject,Notes,Group Membership,E-mail 1 - Type,E-mail 1 - Value,E-mail 2 - Type,E-mail 2 - Value,E-mail 3 - Type,E-mail 3 - Value,IM 1 - Type,IM 1 - Service,IM 1 - Value,Phone 1 - Type,Phone 1 - Value,Phone 2 - Type,Phone 2 - Value,Phone 3 - Type,Phone 3 - Value,Address 1 - Type,Address 1 - Formatted,Address 1 - Street,Address 1 - City,Address 1 - PO Box,Address 1 - Region,Address 1 - Postal Code,Address 1 - Country,Address 1 - Extended Address,Address 2 - Type,Address 2 - Formatted,Address 2 - Street,Address 2 - City,Address 2 - PO Box,Address 2 - Region,Address 2 - Postal Code,Address 2 - Country,Address 2 - Extended Address,Organization 1 - Type,Organization 1 - Name,Organization 1 - Yomi Name,Organization 1 - Title,Organization 1 - Department,Organization 1 - Symbol,Organization 1 - Location,Organization 1 - Job Description,Relation 1 - Type,Relation 1 - Value,Relation 2 - Type,Relation 2 - Value,Relation 3 - Type,Relation 3 - Value,Relation 4 - Type,Relation 4 - Value,Relation 5 - Type,Relation 5 - Value,Website 1 - Type,Website 1 - Value,Website 2 - Type,Website 2 - Value,Website 3 - Type,Website 3 - Value,Website 4 - Type,Website 4 - Value,Website 5 - Type,Website 5 - Value,Website 6 - Type,Website 6 - Value,Website 7 - Type,Website 7 - Value"
"Alpesh Vaghasiya,Alpesh,,Vaghasiya,,,,,,,,,,,1986-09-16,,,,,,,,,,,,Facebook ::: MobilePhone ::: All ::: Office ::: * My Contacts,* Home,me@alpeshvaghasiya.com,Other,alpesh@artoongames.com,Work,alpeshvaghasiya7@gmail.com,,,,Mobile,9727056565,,,,,Home,""Surat, Gujarat"
"India"",,Surat,,Gujarat,,India,,,,,,,,,,,,The Logica,,CEO,,,,,Sister,Kerali Vaghasia,cousin,Kairav Vaghasia,,,,,,,twitter,http://www.twitter.com/asvaghasiya,website,www.artoonsolutions.com,linkedin,http://www.linkedin.com/in/alpeshvaghasiya,facebook,http://www.facebook.com/alpesh.vaghasiya,Personal Website,http://www.alpeshvaghasiya.com,Profile,http://www.google.com/profiles/106299312931371348975,Portfolio,http://artoonsolutions.com/portfolio"
"Anand Lathigara,Anand,,Lathigara,,,,,,,,,,,,,,,,,,,,,,,Facebook ::: All ::: Office ::: * My Contacts,Home,anand.lathigara@gmail.com,Other,anand_lathigara@yahoo.com ::: shyam_love2001@yahoo.com,* Other,lathigraanand@yahoo.in,,,,Home,9228412087,,,,,Home,""Surat, Gujarat"
"India"",,Surat,,Gujarat,,India,,,,,,,,,,,,SMSBrain.in - Send SMS with Sense!,,Relationship Manager,,,,,sister,Krishna Lathigara,cousin,Soni Hemal Lathigara,brother,Abhay Garathiya,,,,,twitter,http://www.twitter.com/AnandLathigara,website,anandlathigara.blogspot.com,linkedin,http://www.linkedin.com/pub/anand-lathigara/52/747/ab8,facebook,http://www.facebook.com/anand.lathigara,Profile,http://www.google.com/profiles/101670297624502753179,,,,"

给定输出:

{"header":[null,"\u0000G\u0000i\u0000v\u0000e\u0000n\u0000 \u0000N\u0000a\u0000m\u0000e\u0000","\u0000A\u0000d\u0000d\u0000i\u0000t\u0000i\u0000o\u0000n\u0000a\u0000l\u0000 \u0000N\u0000a\u0000m\u0000e\u0000","\u0000F\u0000a\u0000m\u0000i\u0000l\u0000y\u0000 \u0000N\u0000a\u0000m\u0000e\u0000","\u0000Y\u0000o\u0000m\u0000i\u0000 \u0000N\u0000a\u0000m\u0000e\u0000","\u0000G\u0000i\u0000v\u0000e\u0000n\u0000 \u0000N\u0000a\u0000m\u0000e\u0000 \u0000Y\u0000o\u0000m\u0000i\u0000","\u0000A\u0000d\u0000d\u0000i\u0000t\u0000i\u0000o\u0000n\u0000a\u0000l\u0000 \u0000N\u0000a\u0000m\u0000e\u0000 \u0000Y\u0000o\u0000m\u0000i\u0000","\u0000F\u0000a\u0000m\u0000i\u0000l\u0000y\u0000 \u0000N\u0000a\u0000m\u0000e\u0000 \u0000Y\u0000o\u0000m\u0000i\u0000","\u0000N\u0000a\u0000m\u0000e\u0000 \u0000P\u0000r\u0000e\u0000f\u0000i\u0000x\u0000","\u0000N\u0000a\u0000m\u0000e\u0000 \u0000S\u0000u\u0000f\u0000f\u0000i\u0000x\u0000","\u0000I\u0000n\u0000i\u0000t\u0000i\u0000a\u0000l\u0000s\u0000","\u0000N\u0000i\u0000c\u0000k\u0000n\u0000a\u0000m\u0000e\u0000","\u0000S\u0000h\u0000o\u0000r\u0000t\u0000 \u0000N\u0000a\u0000m\u0000e\u0000","\u0000M\u0000a\u0000i\u0000d\u0000e\u0000n\u0000 \u0000N\u0000a\u0000m\u0000e\u0000","\u0000B\u0000i\u0000r\u0000t\u0000h\u0000d\u0000a\u0000y\u0000","\u0000G\u0000e\u0000n\u0000d\u0000e\u0000r\u0000","\u0000L\u0000o\u0000c\u0000a\u0000t\u0000i\u0000o\u0000n\u0000","\u0000B\u0000i\u0000l\u0000l\u0000i\u0000n\u0000g\u0000 \u0000I\u0000n\u0000f\u0000o\u0000r\u0000m\u0000a\u0000t\u0000i\u0000o\u0000n\u0000","\u0000D\u0000i\u0000r\u0000e\u0000c\u0000t\u0000o\u0000r\u0000y\u0000 \u0000S\u0000e\u0000r\u0000v\u0000e\u0000r\u0000","\u0000M\u0000i\u0000l\u0000e\u0000a\u0000g\u0000e\u0000","\u0000O\u0000c\u0000c\u0000u\u0000p\u0000a\u0000t\u0000i\u0000o\u0000n\u0000","\u0000H\u0000o\u0000b\u0000b\u0000y\u0000","\u0000S\u0000e\u0000n\u0000s\u0000i\u0000t\u0000i\u0000v\u0000i\u0000t\u0000y\u0000","\u0000P\u0000r\u0000i\u0000o\u0000r\u0000i\u0000t\u0000y\u0000","\u0000S\u0000u\u0000b\u0000j\u0000e\u0000c\u0000t\u0000","\u0000N\u0000o\u0000t\u0000e\u0000s\u0000","\u0000G\u0000r\u0000o\u0000u\u0000p\u0000 \u0000M\u0000e\u0000m\u0000b\u0000e\u0000r\u0000s\u0000h\u0000i\u0000p\u0000","\u0000E\u0000-\u0000m\u0000a\u0000i\u0000l\u0000 \u00001\u0000 \u0000-\u0000 \u0000T\u0000y\u0000p\u0000e\u0000","\u0000E\u0000-\u0000m\u0000a\u0000i\u0000l\u0000 \u00001\u0000 \u0000-\u0000 \u0000V\u0000a\u0000l\u0000u\u0000e\u0000","\u0000E\u0000-\u0000m\u0000a\u0000i\u0000l\u0000 \u00002\u0000 \u0000-\u0000 \u0000T\u0000y\u0000p\u0000e\u0000","\u0000E\u0000-\u0000m\u0000a\u0000i\u0000l\u0000 \u00002\u0000 \u0000-\u0000 \u0000V\u0000a\u0000l\u0000u\u0000e\u0000","\u0000E\u0000-\u0000m\u0000a\u0000i\u0000l\u0000 \u00003\u0000 \u0000-\u0000 \u0000T\u0000y\u0000p\u0000e\u0000","\u0000E\u0000-\u0000m\u0000a\u0000i\u0000l\u0000 \u00003\u0000 \u0000-\u0000 \u0000V\u0000a\u0000l\u0000u\u0000e\u0000","\u0000I\u0000M\u0000 \u00001\u0000 \u0000-\u0000 \u0000T\u0000y\u0000p\u0000e\u0000","\u0000I\u0000M\u0000 \u00001\u0000 \u0000-\u0000 \u0000S\u0000e\u0000r\u0000v\u0000i\u0000c\u0000e\u0000","\u0000I\u0000M\u0000 \u00001\u0000 \u0000-\u0000 \u0000V\u0000a\u0000l\u0000u\u0000e\u0000","\u0000P\u0000h\u0000o\u0000n\u0000e\u0000 \u00001\u0000 \u0000-\u0000 \u0000T\u0000y\u0000p\u0000e\u0000","\u0000P\u0000h\u0000o\u0000n\u0000e\u0000 \u00001\u0000 \u0000-\u0000 \u0000V\u0000a\u0000l\u0000u\u0000e\u0000","\u0000P\u0000h\u0000o\u0000n\u0000e\u0000 \u00002\u0000 \u0000-\u0000 \u0000T\u0000y\u0000p\u0000e\u0000","\u0000P\u0000h\u0000o\u0000n\u0000e\u0000 \u00002\u0000 \u0000-\u0000 \u0000V\u0000a\u0000l\u0000u\u0000e\u0000","\u0000P\u0000h\u0000o\u0000n\u0000e\u0000 \u00003\u0000 \u0000-\u0000 \u0000T\u0000y\u0000p\u0000e\u0000","\u0000P\u0000h\u0000o\u0000n\u0000e\u0000 \u00003\u0000 \u0000-\u0000 \u0000V\u0000a\u0000l\u0000u\u0000e\u0000","\u0000A\u0000d\u0000d\u0000r\u0000e\u0000s\u0000s\u0000 \u00001\u0000 \u0000-\u0000 \u0000T\u0000y\u0000p\u0000e\u0000","\u0000A\u0000d\u0000d\u0000r\u0000e\u0000s\u0000s\u0000 \u00001\u0000 \u0000-\u0000 \u0000F\u0000o\u0000r\u0000m\u0000a\u0000t\u0000t\u0000e\u0000d\u0000","\u0000A\u0000d\u0000d\u0000r\u0000e\u0000s\u0000s\u0000 \u00001\u0000 \u0000-\u0000 \u0000S\u0000t\u0000r\u0000e\u0000e\u0000t\u0000","\u0000A\u0000d\u0000d\u0000r\u0000e\u0000s\u0000s\u0000 \u00001\u0000 \u0000-\u0000 \u0000C\u0000i\u0000t\u0000y\u0000","\u0000A\u0000d\u0000d\u0000r\u0000e\u0000s\u0000s\u0000 \u00001\u0000 \u0000-\u0000 \u0000P\u0000O\u0000 \u0000B\u0000o\u0000x\u0000","\u0000A\u0000d\u0000d\u0000r\u0000e\u0000s\u0000s\u0000 \u00001\u0000 \u0000-\u0000 \u0000R\u0000e\u0000g\u0000i\u0000o\u0000n\u0000","\u0000A\u0000d\u0000d\u0000r\u0000e\u0000s\u0000s\u0000 \u00001\u0000 \u0000-\u0000 \u0000P\u0000o\u0000s\u0000t\u0000a\u0000l\u0000 \u0000C\u0000o\u0000d\u0000e\u0000","\u0000A\u0000d\u0000d\u0000r\u0000e\u0000s\u0000s\u0000 \u00001\u0000 \u0000-\u0000 \u0000C\u0000o\u0000u\u0000n\u0000t\u0000r\u0000y\u0000","\u0000A\u0000d\u0000d\u0000r\u0000e\u0000s\u0000s\u0000 \u00001\u0000 \u0000-\u0000 \u0000E\u0000x\u0000t\u0000e\u0000n\u0000d\u0000e\u0000d\u0000 \u0000A\u0000d\u0000d\u0000r\u0000e\u0000s\u0000s\u0000","\u0000A\u0000d\u0000d\u0000r\u0000e\u0000s\u0000s\u0000 \u00002\u0000 \u0000-\u0000 \u0000T\u0000y\u0000p\u0000e\u0000","\u0000A\u0000d\u0000d\u0000r\u0000e\u0000s\u0000s\u0000 \u00002\u0000 \u0000-\u0000 \u0000F\u0000o\u0000r\u0000m\u0000a\u0000t\u0000t\u0000e\u0000d\u0000","\u0000A\u0000d\u0000d\u0000r\u0000e\u0000s\u0000s\u0000 \u00002\u0000 \u0000-\u0000 \u0000S\u0000t\u0000r\u0000e\u0000e\u0000t\u0000","\u0000A\u0000d\u0000d\u0000r\u0000e\u0000s\u0000s\u0000 \u00002\u0000 \u0000-\u0000 \u0000C\u0000i\u0000t\u0000y\u0000","\u0000A\u0000d\u0000d\u0000r\u0000e\u0000s\u0000s\u0000 \u00002\u0000 \u0000-\u0000 \u0000P\u0000O\u0000 \u0000B\u0000o\u0000x\u0000","\u0000A\u0000d\u0000d\u0000r\u0000e\u0000s\u0000s\u0000 \u00002\u0000 \u0000-\u0000 \u0000R\u0000e\u0000g\u0000i\u0000o\u0000n\u0000","\u0000A\u0000d\u0000d\u0000r\u0000e\u0000s\u0000s\u0000 \u00002\u0000 \u0000-\u0000 \u0000P\u0000o\u0000s\u0000t\u0000a\u0000l\u0000 \u0000C\u0000o\u0000d\u0000e\u0000","\u0000A\u0000d\u0000d\u0000r\u0000e\u0000s\u0000s\u0000 \u00002\u0000 \u0000-\u0000 \u0000C\u0000o\u0000u\u0000n\u0000t\u0000r\u0000y\u0000","\u0000A\u0000d\u0000d\u0000r\u0000e\u0000s\u0000s\u0000 \u00002\u0000 \u0000-\u0000 \u0000E\u0000x\u0000t\u0000e\u0000n\u0000d\u0000e\u0000d\u0000 \u0000A\u0000d\u0000d\u0000r\u0000e\u0000s\u0000s\u0000","\u0000O\u0000r\u0000g\u0000a\u0000n\u0000i\u0000z\u0000a\u0000t\u0000i\u0000o\u0000n\u0000 \u00001\u0000 \u0000-\u0000 \u0000T\u0000y\u0000p\u0000e\u0000","\u0000O\u0000r\u0000g\u0000a\u0000n\u0000i\u0000z\u0000a\u0000t\u0000i\u0000o\u0000n\u0000 \u00001\u0000 \u0000-\u0000 \u0000N\u0000a\u0000m\u0000e\u0000","\u0000O\u0000r\u0000g\u0000a\u0000n\u0000i\u0000z\u0000a\u0000t\u0000i\u0000o\u0000n\u0000 \u00001\u0000 \u0000-\u0000 \u0000Y\u0000o\u0000m\u0000i\u0000 \u0000N\u0000a\u0000m\u0000e\u0000","\u0000O\u0000r\u0000g\u0000a\u0000n\u0000i\u0000z\u0000a\u0000t\u0000i\u0000o\u0000n\u0000 \u00001\u0000 \u0000-\u0000 \u0000T\u0000i\u0000t\u0000l\u0000e\u0000","\u0000O\u0000r\u0000g\u0000a\u0000n\u0000i\u0000z\u0000a\u0000t\u0000i\u0000o\u0000n\u0000 \u00001\u0000 \u0000-\u0000 \u0000D\u0000e\u0000p\u0000a\u0000r\u0000t\u0000m\u0000e\u0000n\u0000t\u0000","\u0000O\u0000r\u0000g\u0000a\u0000n\u0000i\u0000z\u0000a\u0000t\u0000i\u0000o\u0000n\u0000 \u00001\u0000 \u0000-\u0000 \u0000S\u0000y\u0000m\u0000b\u0000o\u0000l\u0000","\u0000O\u0000r\u0000g\u0000a\u0000n\u0000i\u0000z\u0000a\u0000t\u0000i\u0000o\u0000n\u0000 \u00001\u0000 \u0000-\u0000 \u0000L\u0000o\u0000c\u0000a\u0000t\u0000i\u0000o\u0000n\u0000","\u0000O\u0000r\u0000g\u0000a\u0000n\u0000i\u0000z\u0000a\u0000t\u0000i\u0000o\u0000n\u0000 \u00001\u0000 \u0000-\u0000 \u0000J\u0000o\u0000b\u0000 \u0000D\u0000e\u0000s\u0000c\u0000r\u0000i\u0000p\u0000t\u0000i\u0000o\u0000n\u0000","\u0000R\u0000e\u0000l\u0000a\u0000t\u0000i\u0000o\u0000n\u0000 \u00001\u0000 \u0000-\u0000 \u0000T\u0000y\u0000p\u0000e\u0000","\u0000R\u0000e\u0000l\u0000a\u0000t\u0000i\u0000o\u0000n\u0000 \u00001\u0000 \u0000-\u0000 \u0000V\u0000a\u0000l\u0000u\u0000e\u0000","\u0000R\u0000e\u0000l\u0000a\u0000t\u0000i\u0000o\u0000n\u0000 \u00002\u0000 \u0000-\u0000 \u0000T\u0000y\u0000p\u0000e\u0000","\u0000R\u0000e\u0000l\u0000a\u0000t\u0000i\u0000o\u0000n\u0000 \u00002\u0000 \u0000-\u0000 \u0000V\u0000a\u0000l\u0000u\u0000e\u0000","\u0000R\u0000e\u0000l\u0000a\u0000t\u0000i\u0000o\u0000n\u0000 \u00003\u0000 \u0000-\u0000 \u0000T\u0000y\u0000p\u0000e\u0000","\u0000R\u0000e\u0000l\u0000a\u0000t\u0000i\u0000o\u0000n\u0000 \u00003\u0000 \u0000-\u0000 \u0000V\u0000a\u0000l\u0000u\u0000e\u0000","\u0000R\u0000e\u0000l\u0000a\u0000t\u0000i\u0000o\u0000n\u0000 \u00004\u0000 \u0000-\u0000 \u0000T\u0000y\u0000p\u0000e\u0000","\u0000R\u0000e\u0000l\u0000a\u0000t\u0000i\u0000o\u0000n\u0000 \u00004\u0000 \u0000-\u0000 \u0000V\u0000a\u0000l\u0000u\u0000e\u0000","\u0000R\u0000e\u0000l\u0000a\u0000t\u0000i\u0000o\u0000n\u0000 \u00005\u0000 \u0000-\u0000 \u0000T\u0000y\u0000p\u0000e\u0000","\u0000R\u0000e\u0000l\u0000a\u0000t\u0000i\u0000o\u0000n\u0000 \u00005\u0000 \u0000-\u0000 \u0000V\u0000a\u0000l\u0000u\u0000e\u0000","\u0000W\u0000e\u0000b\u0000s\u0000i\u0000t\u0000e\u0000 \u00001\u0000 \u0000-\u0000 \u0000T\u0000y\u0000p\u0000e\u0000","\u0000W\u0000e\u0000b\u0000s\u0000i\u0000t\u0000e\u0000 \u00001\u0000 \u0000-\u0000 \u0000V\u0000a\u0000l\u0000u\u0000e\u0000","\u0000W\u0000e\u0000b\u0000s\u0000i\u0000t\u0000e\u0000 \u00002\u0000 \u0000-\u0000 \u0000T\u0000y\u0000p\u0000e\u0000","\u0000W\u0000e\u0000b\u0000s\u0000i\u0000t\u0000e\u0000 \u00002\u0000 \u0000-\u0000 \u0000V\u0000a\u0000l\u0000u\u0000e\u0000","\u0000W\u0000e\u0000b\u0000s\u0000i\u0000t\u0000e\u0000 \u00003\u0000 \u0000-\u0000 \u0000T\u0000y\u0000p\u0000e\u0000","\u0000W\u0000e\u0000b\u0000s\u0000i\u0000t\u0000e\u0000 \u00003\u0000 \u0000-\u0000 \u0000V\u0000a\u0000l\u0000u\u0000e\u0000","\u0000W\u0000e\u0000b\u0000s\u0000i\u0000t\u0000e\u0000 \u00004\u0000 \u0000-\u0000 \u0000T\u0000y\u0000p\u0000e\u0000","\u0000W\u0000e\u0000b\u0000s\u0000i\u0000t\u0000e\u0000 \u00004\u0000 \u0000-\u0000 \u0000V\u0000a\u0000l\u0000u\u0000e\u0000","\u0000W\u0000e\u0000b\u0000s\u0000i\u0000t\u0000e\u0000 \u00005\u0000 \u0000-\u0000 \u0000T\u0000y\u0000p\u0000e\u0000","\u0000W\u0000e\u0000b\u0000s\u0000i\u0000t\u0000e\u0000 \u00005\u0000 \u0000-\u0000 \u0000V\u0000a\u0000l\u0000u\u0000e\u0000","\u0000W\u0000e\u0000b\u0000s\u0000i\u0000t\u0000e\u0000 \u00006\u0000 \u0000-\u0000 \u0000T\u0000y\u0000p\u0000e\u0000","\u0000W\u0000e\u0000b\u0000s\u0000i\u0000t\u0000e\u0000 \u00006\u0000 \u0000-\u0000 \u0000V\u0000a\u0000l\u0000u\u0000e\u0000","\u0000W\u0000e\u0000b\u0000s\u0000i\u0000t\u0000e\u0000 \u00007\u0000 \u0000-\u0000 \u0000T\u0000y\u0000p\u0000e\u0000","\u0000W\u0000e\u0000b\u0000s\u0000i\u0000t\u0000e\u0000 \u00007\u0000 \u0000-\u0000 \u0000V\u0000a\u0000l\u0000u\u0000e\u0000\"\u0000\r\u0000"],"firstRow":["\u0000\"\u0000A\u0000l\u0000p\u0000e\u0000s\u0000h\u0000 \u0000V\u0000a\u0000g\u0000h\u0000a\u0000s\u0000i\u0000y\u0000a\u0000","\u0000A\u0000l\u0000p\u0000e\u0000s\u0000h\u0000","\u0000","\u0000V\u0000a\u0000g\u0000h\u0000a\u0000s\u0000i\u0000y\u0000a\u0000","\u0000","\u0000","\u0000","\u0000","\u0000","\u0000","\u0000","\u0000","\u0000","\u0000","\u00001\u00009\u00008\u00006\u0000-\u00000\u00009\u0000-\u00001\u00006\u0000","\u0000","\u0000","\u0000","\u0000","\u0000","\u0000","\u0000","\u0000","\u0000","\u0000","\u0000","\u0000F\u0000a\u0000c\u0000e\u0000b\u0000o\u0000o\u0000k\u0000 \u0000:\u0000:\u0000:\u0000 \u0000M\u0000o\u0000b\u0000i\u0000l\u0000e\u0000P\u0000h\u0000o\u0000n\u0000e\u0000 \u0000:\u0000:\u0000:\u0000 \u0000A\u0000l\u0000l\u0000 \u0000:\u0000:\u0000:\u0000 \u0000O\u0000f\u0000f\u0000i\u0000c\u0000e\u0000 \u0000:\u0000:\u0000:\u0000 \u0000*\u0000 \u0000M\u0000y\u0000 \u0000C\u0000o\u0000n\u0000t\u0000a\u0000c\u0000t\u0000s\u0000","\u0000*\u0000 \u0000H\u0000o\u0000m\u0000e\u0000","\u0000m\u0000e\u0000@\u0000a\u0000l\u0000p\u0000e\u0000s\u0000h\u0000v\u0000a\u0000g\u0000h\u0000a\u0000s\u0000i\u0000y\u0000a\u0000.\u0000c\u0000o\u0000m\u0000","\u0000O\u0000t\u0000h\u0000e\u0000r\u0000","\u0000a\u0000l\u0000p\u0000e\u0000s\u0000h\u0000@\u0000a\u0000r\u0000t\u0000o\u0000o\u0000n\u0000g\u0000a\u0000m\u0000e\u0000s\u0000.\u0000c\u0000o\u0000m\u0000","\u0000W\u0000o\u0000r\u0000k\u0000","\u0000a\u0000l\u0000p\u0000e\u0000s\u0000h\u0000v\u0000a\u0000g\u0000h\u0000a\u0000s\u0000i\u0000y\u0000a\u00007\u0000@\u0000g\u0000m\u0000a\u0000i\u0000l\u0000.\u0000c\u0000o\u0000m\u0000","\u0000","\u0000","\u0000","\u0000M\u0000o\u0000b\u0000i\u0000l\u0000e\u0000","\u00009\u00007\u00002\u00007\u00000\u00005\u00006\u00005\u00006\u00005\u0000","\u0000","\u0000","\u0000","\u0000","\u0000H\u0000o\u0000m\u0000e\u0000","\u0000\"\u0000\"\u0000S\u0000u\u0000r\u0000a\u0000t\u0000","\u0000 \u0000G\u0000u\u0000j\u0000a\u0000r\u0000a\u0000t\u0000\"\u0000\r\u0000"]}

请帮忙..

4

1 回答 1

0

是的,我得到了答案。

<?php 

    $fp = fopen("google12.csv", 'r');

    $fileHeader = array();
    $firstRow = array();
    $index = 0;
    while (($data = fgetcsv($fp)) !== FALSE && $index != 2)
    {
        $data = preg_replace('/[^a-zA-Z0-9_ %\[\]\.\(\)%&-]/s', '', $data); // add line
        if ($index == 0)
            $fileHeader = $data;
        elseif ($index == 1)
            $firstRow = $data;

        $index++;
    }

    fclose($fp);

    $parameter = array("header" => $fileHeader,"firstRow" => $firstRow);

    echo json_encode($parameter);
    exit;

?>

输出 :

{"header":["Name","Given Name","Additional Name","Family Name","Yomi Name","Given Name Yomi","Additional Name Yomi","Family Name Yomi","Name Prefix","Name Suffix","Initials","Nickname","Short Name","Maiden Name","Birthday","Gender","Location","Billing Information","Directory Server","Mileage","Occupation","Hobby","Sensitivity","Priority","Subject","Notes","Group Membership","E-mail 1 - Type","E-mail 1 - Value","E-mail 2 - Type","E-mail 2 - Value","E-mail 3 - Type","E-mail 3 - Value","IM 1 - Type","IM 1 - Service","IM 1 - Value","Phone 1 - Type","Phone 1 - Value","Phone 2 - Type","Phone 2 - Value","Phone 3 - Type","Phone 3 - Value","Address 1 - Type","Address 1 - Formatted","Address 1 - Street","Address 1 - City","Address 1 - PO Box","Address 1 - Region","Address 1 - Postal Code","Address 1 - Country","Address 1 - Extended Address","Address 2 - Type","Address 2 - Formatted","Address 2 - Street","Address 2 - City","Address 2 - PO Box","Address 2 - Region","Address 2 - Postal Code","Address 2 - Country","Address 2 - Extended Address","Organization 1 - Type","Organization 1 - Name","Organization 1 - Yomi Name","Organization 1 - Title","Organization 1 - Department","Organization 1 - Symbol","Organization 1 - Location","Organization 1 - Job Description","Relation 1 - Type","Relation 1 - Value","Relation 2 - Type","Relation 2 - Value","Relation 3 - Type","Relation 3 - Value","Relation 4 - Type","Relation 4 - Value","Relation 5 - Type","Relation 5 - Value","Website 1 - Type","Website 1 - Value","Website 2 - Type","Website 2 - Value","Website 3 - Type","Website 3 - Value","Website 4 - Type","Website 4 - Value","Website 5 - Type","Website 5 - Value","Website 6 - Type","Website 6 - Value","Website 7 - Type","Website 7 - Value"],"firstRow":["Alpesh Vaghasiya","Alpesh","","Vaghasiya","","","","","","","","","","","1986-09-16","","","","","","","","","","","","Facebook MobilePhone All Office My Contacts"," Home","mealpeshvaghasiya.com","Other","alpeshartoongames.com","Work","alpeshvaghasiya7gmail.com","","","","Mobile","9727056565","","","","","Home","Surat"," Gujarat"]}
于 2013-02-21T11:23:14.147 回答