{"id":39340848,"url":"https://github.com/seankndy/phpcsv","last_synced_at":"2026-01-18T02:17:03.130Z","repository":{"id":57048134,"uuid":"132196402","full_name":"seankndy/phpcsv","owner":"seankndy","description":"PHP package for working with CSV data","archived":false,"fork":false,"pushed_at":"2019-03-08T18:23:11.000Z","size":56,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-01T10:22:52.877Z","etag":null,"topics":["csv","csv-data","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/seankndy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-05-04T22:56:25.000Z","updated_at":"2019-03-08T18:23:13.000Z","dependencies_parsed_at":"2022-08-23T18:51:00.968Z","dependency_job_id":null,"html_url":"https://github.com/seankndy/phpcsv","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/seankndy/phpcsv","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seankndy%2Fphpcsv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seankndy%2Fphpcsv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seankndy%2Fphpcsv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seankndy%2Fphpcsv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/seankndy","download_url":"https://codeload.github.com/seankndy/phpcsv/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seankndy%2Fphpcsv/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28526569,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-18T00:39:45.795Z","status":"online","status_checked_at":"2026-01-18T02:00:07.578Z","response_time":98,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csv","csv-data","php"],"created_at":"2026-01-18T02:17:03.050Z","updated_at":"2026-01-18T02:17:03.111Z","avatar_url":"https://github.com/seankndy.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"phpcsv is a small PHP package to assist in dealing with CSV data.\n\nIt is not meant to be full-featured or very high-performance.  I regularly need\nto manipulate one-off CSV data and so I built this to assist in the common\nthings I keep re-writing like formatting a date or merging 2 CSVs together.\n\nA few examples:\n\n\nSelectively join data from one CSV into another.\n\nThis would look at the 'id' column in file.csv and match it with 'fid' column\nin other_file.csv then take the 'username' column from other_file.csv and\nfill it into the 'user' column of file.csv.  then dump changes to stdout.\n\nIt is similar to an SQL join, for example:\n  select file.*, other_file.username from file\n  left join other_file on file.id = other_file.fid\n```\nuse SeanKndy\\CSV\\CSV;\n\n$csv = new CSV('file.csv');\n$csv-\u003ejoin(\n    new CSV('other_file.csv'),\n    function ($r1, $r2) {\n        return ($r1-\u003eget('id') == $r2-\u003eget('fid'));\n    },\n    ['user'],\n    ['username']\n));\n$csv-\u003egetRecords()-\u003edump();\n```\n\nFormat a date column, dump output:\n```\nuse SeanKndy\\CSV\\CSV;\nuse SeanKndy\\CSV\\Formatters;\n\n$csv = new CSV('file.csv');\n$csv-\u003esetFormatter('date_of_birth', function($data) {\n    return Formatters::date($data, 'm/d/Y');\n});\n$csv-\u003egetRecords()-\u003edump();\n```\n\nLoop through file without loading into memory:\n```\nuse SeanKndy\\CSV\\CSV;\n\nforeach (new CSV('file.csv', ['preload' =\u003e false])-\u003egetRecords() as $record) {\n    print_r($record-\u003egetAll());\n}\n```\n\nSelectively print columns in arbitrary order:\n```\nuse SeanKndy\\CSV\\CSV;\n\n$csv = new CSV('file.csv');\n$csv-\u003egetRecords()-\u003epickyDump(['age','dob','name','sex']);\n```\n\nMerge 2 columns together, separate by space. print changes to stdout\n```\nuse SeanKndy\\CSV\\CSV;\n\n$csv = new CSV('file.csv');\n$csv-\u003ecombineColumns(['first_name','last_name'], 'name');\n$csv-\u003egetRecords()-\u003edump();\n```\n\nManually get or set data from a record. Note that this only works\nif you're NOT using mutators!  If mutators are in use, then get() will\nreturn a clone/copy of that data post-mutated.\n```\nuse SeanKndy\\CSV\\CSV;\n\n$csv = new CSV('file.csv');\nforeach ($csv-\u003egetRecords() as $record) {\n    $age = $record-\u003eget('age');\n    if ($age \u003e= 18) {\n        $record-\u003eset('is_adult', 'yes');\n    }\n}\n```\n\nFilter records (in this case, any record where 'sex' column is not 'male'\nwould be removed):\n```\nuse SeanKndy\\CSV\\CSV;\n\n$csv = new CSV('file.csv');\n$csv-\u003egetRecords()-\u003efilter(['sex' =\u003e 'male'])-\u003edump();\n```\n\nExample of adding a custom Mutator to manipulate some data in records.  In this\ncase, we make sure the comma-separate Rate Group(s) column is paired with the\nsame number of Billing Frequency items:\n```\nuse SeanKndy\\CSV\\CSV;\nuse SeanKndy\\CSV\\Record;\nuse SeanKndy\\CSV\\Mutators\\Mutator;\n\n$csv = new CSV('customers.csv');\n$csv-\u003eaddMutator(new class extends Mutator {\n    public function mutate(Record $record) {\n        $rateGroups = preg_split('/,\\s*/', $record-\u003eget('Rate Group(s)'));\n        $billingFrequency = preg_split('/,\\s*/', $record-\u003eget('Billing Frequency');\n\n        if (count($rateGroups) \u003e count($billingFrequency)) {\n            // ex: if Rate Group(s) is '500,501,502' and Billing Frequency is '12'\n            // then this would update Billing Frequency to be '12,12,12' to pair\n            // with each of the Rate Group(s)\n            for ($i = count($billingFrequency); $i \u003c count($rateGroups); $i++) {\n                $billingFrequency[] = $billingFrequency[0];\n            }\n            $record-\u003eset('Billing Frequency', implode(',', $billingFrequency));\n        } else if (count($rateGroups) \u003c count($billingFrequency)) {\n            $billingFrequency = array_splice($billingFrequency, count($rateGroups));\n            $record-\u003eset('Billing Frequency', implode(',', $billingFrequency));\n        }\n\n        return $record;\n    }\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseankndy%2Fphpcsv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fseankndy%2Fphpcsv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseankndy%2Fphpcsv/lists"}