{"id":22034962,"url":"https://github.com/bpacholek/php-csv-writer","last_synced_at":"2025-03-23T12:24:18.586Z","repository":{"id":56988879,"uuid":"221347153","full_name":"bpacholek/php-csv-writer","owner":"bpacholek","description":"Basic CsvWriter based on a buffered TextWriter (also provided).","archived":false,"fork":false,"pushed_at":"2020-01-21T19:02:12.000Z","size":23,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-02T01:54:33.650Z","etag":null,"topics":["csv","csv-converter","csv-export","csv-files","csv-format","csv-parser","csv-parsing","csvwriter"],"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/bpacholek.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":"2019-11-13T01:34:12.000Z","updated_at":"2020-01-21T19:01:43.000Z","dependencies_parsed_at":"2022-08-21T09:40:44.925Z","dependency_job_id":null,"html_url":"https://github.com/bpacholek/php-csv-writer","commit_stats":null,"previous_names":["bpacholek/php-csv-writer","idct-tech/php-csv-writer"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bpacholek%2Fphp-csv-writer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bpacholek%2Fphp-csv-writer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bpacholek%2Fphp-csv-writer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bpacholek%2Fphp-csv-writer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bpacholek","download_url":"https://codeload.github.com/bpacholek/php-csv-writer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245099758,"owners_count":20560661,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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-converter","csv-export","csv-files","csv-format","csv-parser","csv-parsing","csvwriter"],"created_at":"2024-11-30T10:15:09.049Z","updated_at":"2025-03-23T12:24:18.564Z","avatar_url":"https://github.com/bpacholek.png","language":"PHP","readme":"\n# PHP CSV Writer\nBasic CsvWriter based on a buffered TextWriter (also provided).\nSupports buffering in memory and proper handling of EOL setting which is not available easily with native `fputcsv` function.\n\n![Tests status](https://github.com/ideaconnect/php-csv-writer/workflows/All%20tests%20using%20PHPUnit/badge.svg) [![Coverage Status](https://coveralls.io/repos/github/ideaconnect/php-csv-writer/badge.svg?branch=master)](https://coveralls.io/github/ideaconnect/php-csv-writer?branch=master) ![GitHub tag (latest SemVer)](https://img.shields.io/github/v/tag/ideaconnect/php-csv-writer?label=latest%20version\u0026sort=semver)\n\nMain purpose of this library is to provide an object-oriented way of buffered CSV files writing.\n\n## Installation\nThe best way to install the library in your project is by using **Composer**:\n```bash\ncomposer require idct/php-csv-writer\n```\nof course you can still manually include all the required files in your project using `using` statements yet **Composer** and autoloading is more than suggested.\n## Usage\nCreate an instance:\n```php\nuse IDCT\\CsvWriter\\CsvWriter;\n$csvWriter = new CsvWriter();\n```\n\nNow you need to open or create a file, to do so you have two methods available: **open** and **openWithFieldsNames**\nTo create a new file with without adding headers in the first line use:\n```php\n$csvWriter-\u003eopen('filename.csv');\n```\n\nTo open a new file with fields' names added in the first line pass an array as the second argument:\n```php\n$csvWriter-\u003eopenWithFieldsNames('filename.csv', [\"columnA\", \"columnB\", \"columnC\"]);\n```\n\n**When writing a new line (adding data) to a CSV file opened with fields names then columns count number is verified on each attempt.**\n\nIt is possible to appened into existing files by passing __TextWriter::FILEMODE_APPEND__ as the last argument.\n```php\n$csvWriter-\u003eopen('filename.csv', CsvWriter::FILEMODE_APPEND);\n```\nor:\n```php\n$csvWriter-\u003eopenWithFieldsNames('filename.csv', [\"columnA\", \"columnB\", \"columnC\"], CsvWriter::FILEMODE_APPEND);\n```\n**Warning: in append mode lines are NOT added as the first line of the CSV file, they are used only for verification of columns count during write operations.**\n\n### Buffering \nBy default **CsvWriter** has buffering disabled, you can enable it by providing buffer size (in bytes) using method **setBufferSize**.\nBe sure to understand that data is actually saved in the file only when buffer is filled so be sure to close the file using **close** method or use **flush** whenever you want to intentionally flush the buffer into the file without closing it.\n### EOL support\nBy default PHP's internal `fputcsv` function uses default EOL symbol for the current platform. `idct/php-csv-writer` supports setting different EOL symbols:\npass `CsvWriter::EOL_WINDOWS`, `CsvWriter::EOL_LINUX` or `CsvWriter::EOL_MACLEGACY` (Mac today uses LINUX EOL, this is just for legacy support) to **setEolSymbol** method.\n**Warning:** the EOL symbol will be used only for **NEXT** lines, previous ones (already existing in the file or buffer) will remain intact.\n### TextWriter \nCsvWriter is based on **TextWriter** which can be used for buffered text write operations. Apart from the methods described above it provides also different behavior for `write` and `writeln` operations which store the text or write it followed by the defined EOL symbol respectively.\nTo use it just create an instance:\n```php\n$textWriter = new TextWriter();\n```\n## TODO / Contribution\nAt the moment the main requirement is to provide better unit tests and documentation, yet if you find any bugs or have potential feature ideas then please use Issues or Pull Requests, it is more than welcome! I will try to reply ASAP.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbpacholek%2Fphp-csv-writer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbpacholek%2Fphp-csv-writer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbpacholek%2Fphp-csv-writer/lists"}