{"id":19951302,"url":"https://github.com/palmtreephp/csv","last_synced_at":"2026-06-02T20:32:07.947Z","repository":{"id":57035275,"uuid":"71888604","full_name":"palmtreephp/csv","owner":"palmtreephp","description":":palm_tree: CSV Reader and Writer","archived":false,"fork":false,"pushed_at":"2025-11-28T12:00:39.000Z","size":230,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-03-16T05:34:44.710Z","etag":null,"topics":["composer-package","csv","csv-parser","csv-reader","csv-writer","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/palmtreephp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-10-25T11:05:16.000Z","updated_at":"2025-11-28T12:00:43.000Z","dependencies_parsed_at":"2022-08-23T20:50:53.971Z","dependency_job_id":null,"html_url":"https://github.com/palmtreephp/csv","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"purl":"pkg:github/palmtreephp/csv","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/palmtreephp%2Fcsv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/palmtreephp%2Fcsv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/palmtreephp%2Fcsv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/palmtreephp%2Fcsv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/palmtreephp","download_url":"https://codeload.github.com/palmtreephp/csv/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/palmtreephp%2Fcsv/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33500456,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-25T14:31:05.219Z","status":"ssl_error","status_checked_at":"2026-05-25T14:31:02.878Z","response_time":57,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["composer-package","csv","csv-parser","csv-reader","csv-writer","php"],"created_at":"2024-11-13T01:07:29.167Z","updated_at":"2026-06-02T20:32:07.929Z","avatar_url":"https://github.com/palmtreephp.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Palmtree CSV\n\n[![License](http://img.shields.io/packagist/l/palmtree/csv.svg)](LICENSE)\n[![Build Status](https://img.shields.io/scrutinizer/build/g/palmtreephp/csv)](https://scrutinizer-ci.com/g/palmtreephp/csv/build-status/master)\n[![Code Quality](https://img.shields.io/scrutinizer/quality/g/palmtreephp/csv)](https://scrutinizer-ci.com/g/palmtreephp/csv/)\n[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/palmtreephp/csv.svg)](https://scrutinizer-ci.com/g/palmtreephp/csv/code-structure/master/code-coverage)\n\nA CSV reader and writer for PHP.\n\nThe `Reader` class implements the `Iterator` interface, loading one line into memory at a time. This means large files can be parsed\nwithout hitting any memory limits.\n\n## Requirements\n* PHP \u003e= 7.4\n\n## Installation\nUse composer to add the package to your dependencies:\n\n```bash\ncomposer require palmtree/csv\n```\n\n## Usage\n\n### Reading\n\n#### Reading from a CSV File\n\n```php\n$csv = new Reader('people.csv');\n\nforeach($csv as $row) {\n    $name = $row['name'];\n    if (isset($row['age'])) {\n        echo \"age is set!\";\n    }\n}\n```\n\n#### Normalize Data Types\nA number of different normalizers can be used to convert data from strings into certain data types.\nBelow is contrived example using some of the currently bundled normalizers:\n\n```php\n$csv = new Reader('/path/to/products.csv');\n\n$csv-\u003eaddNormalizers([\n    // Convert to integer\n    'product_id' =\u003e new NumberNormalizer(),\n\n    // Keep data as string but trim it\n    'name' =\u003e new StringNormalizer(),\n\n    // Convert to float, rounded to 4 decimal places\n    'price' =\u003e NumberNormalizer::create()-\u003escale(4),\n\n    // Convert to boolean true or false\n    'enabled' =\u003e new BooleanNormalizer(),\n\n    // Convert to an array of integers\n    'related_product_ids' =\u003e new ArrayNormalizer(new NumberNormalizer()),\n\n    // Custom conversion with a callback\n    'specials' =\u003e new CallableNormalizer(fn ($value) =\u003e json_decode($value)),\n]);\n```\n\n#### No Headers\nIf your CSV contains no headers pass `false` as the second argument to the constructor:\n\n```php\n$csv = new Reader('people.csv', false);\n\n// Alternatively, call the setHasHeaders() method after instantiation:\n//$csv-\u003esetHasHeaders(false);\n\n```\n\n#### Header Offset\nIf your CSV headers are not on the first row you may specify the (zero based) row offset:\n\n```php\n$csv = new Reader('people.csv');\n// Headers are on the second row so let's set the offset to 1\n$csv-\u003esetHeaderOffset(1);\n```\n\n#### Inline Reading\nYou may use the `InlineReader` to parse a CSV string rather than a file, if it was obtained from an API call or some other means:\n\n```php\n$csv = new \\Palmtree\\Csv\\InlineReader('\"header_1\",\"header_2\"' . \"\\r\\n\" . '\"foo\",\"bar\"');\n```\n\n### Writing\n\n#### Build and Download a CSV File\n\n```php\n$people   = [];\n$people[] = [\n    'name'   =\u003e 'Alice',\n    'age'    =\u003e '24',\n    'gender' =\u003e 'Female',\n];\n$people[] = [\n    'name'   =\u003e 'Bob',\n    'age'    =\u003e '28',\n    'gender' =\u003e 'Male',\n];\n\nDownloader::download('filename.csv', $people);\n```\n\n#### Writing to a CSV File\n\n```php\n$people   = [];\n$people[] = [\n    'name'   =\u003e 'Alice',\n    'age'    =\u003e '24',\n    'gender' =\u003e 'Female',\n];\n$people[] = [\n    'name'   =\u003e 'Bob',\n    'age'    =\u003e '28',\n    'gender' =\u003e 'Male',\n];\n\n\nWriter::write('/path/to/output.csv', $people);\n```\n\nSee the [examples](examples) directory for more usage examples.\n\n## Advanced Usage\n\n#### CSV Control\nYou can access the document object to change the CSV delimiter, enclosure and escape character:\n\n```php\n$csv = new Reader('/path/to/input.csv');\n\n$csv-\u003esetDelimiter(\"\\t\");\n$csv-\u003esetEnclosure('\"');\n$csv-\u003esetEscapeCharacter(\"\\\\\");\n```\n\n#### Line Endings\nCSVs default to `\\r\\n` line endings. Access the document object if you need to change this:\n\n```php\n$csv = new Writer('/path/to/output.csv');\n$csv-\u003egetDocument()-\u003esetLineEnding(\"\\n\");\n```\n\n\n#### Fine-grained Control\nThe document object extends PHP's [SplFileObject](http://php.net/manual/en/class.splfileobject.php) and inherits its methods:\n\n```php\n$csv = new Reader('/path/to/input.csv');\n$csv-\u003egetDocument()-\u003esetFlags(\\SplFileObject::DROP_NEW_LINE);\n```\n\n## Configuration\nIf you're trying to read a CSV file in or generated by an old Mac computer you may need to include\nthe following snippet before creating a new `Reader` instance:\n\n```php\nif (!ini_get('auto_detect_line_endings')) {\n    ini_set('auto_detect_line_endings', '1');\n}\n```\n\nThis is because Macs used to use `\\r` as a line separator. See [here](http://php.net/manual/en/function.fgetcsv.php#refsect1-function.fgetcsv-returnvalues) for more details.\n\n## License\nReleased under the [MIT license](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpalmtreephp%2Fcsv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpalmtreephp%2Fcsv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpalmtreephp%2Fcsv/lists"}