{"id":23114201,"url":"https://github.com/buibr/csv-helper","last_synced_at":"2025-07-04T13:04:14.820Z","repository":{"id":62498075,"uuid":"174109486","full_name":"buibr/csv-helper","owner":"buibr","description":"Parser/Builder of CSV data to file/file to data","archived":false,"fork":false,"pushed_at":"2024-07-12T15:29:49.000Z","size":55,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-18T07:06:37.535Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/buibr.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":"2019-03-06T09:02:37.000Z","updated_at":"2024-07-12T15:29:52.000Z","dependencies_parsed_at":"2022-11-02T12:15:59.934Z","dependency_job_id":null,"html_url":"https://github.com/buibr/csv-helper","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/buibr%2Fcsv-helper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/buibr%2Fcsv-helper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/buibr%2Fcsv-helper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/buibr%2Fcsv-helper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/buibr","download_url":"https://codeload.github.com/buibr/csv-helper/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230056275,"owners_count":18165899,"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":[],"created_at":"2024-12-17T03:20:19.641Z","updated_at":"2024-12-17T03:20:21.665Z","avatar_url":"https://github.com/buibr.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CSV Helper\n\nCSV Helper is a robust parser/builder for converting CSV data to arrays and vice versa. This tool is designed for handling large CSV datasets efficiently.\n\n## Features\n\n- Parse CSV files into arrays.\n- Extract specific columns from CSV files.\n- Iterate through CSV records seamlessly.\n- Build CSV files from arrays.\n\n## Installation\n\nThe preferred method of installing this extension is through [Composer](http://getcomposer.org/download/).\n\nYou can install the package by running the following command:\n\n```sh\ncomposer require --prefer-dist buibr/csv-helper \"^1.5\"\n```\n\nAlternatively, you can add it directly to the `require` section of your `composer.json` file:\n\n```json\n\"require\": {\n    \"buibr/csv-helper\": \"*\"\n}\n```\n\n## Usage\n\n### Parse CSV Data\n\n#### Get Data as Array\n\nTo parse a CSV file and get the data as an array:\n\n```php\n\u003c?php \nuse buibr\\csvhelper\\CsvParser;\n\n$parser = new CsvParser('path/to/file');\n$data   = $parser-\u003efromFile()-\u003etoArray();\n?\u003e\n```\n\n#### Get Data as Array from File\n\nAlternatively, you can parse the CSV file and directly get the data as an array in a single line:\n\n```php\n\u003c?php \nuse buibr\\csvhelper\\CsvParser;\n\n$data = (new CsvParser)-\u003efromFile('path/to/file')-\u003etoArray();\n?\u003e\n```\n\n### Extract Specific Columns\n\n#### Get Only One Column as a One-Dimensional Array\n\nConsider the following `file.csv`:\n\n```csv\nname,email,phone\naaa,bbb,ccc\nddd,eee,fff\nggg,hhh,iii\n```\n\nTo extract the `email` column:\n\n```php\n\u003c?php\nuse buibr\\csvhelper\\CsvParser;\n\n$data = (new CsvParser)-\u003efromFile('path/to/file')-\u003etoColumn('email');\n?\u003e\n```\n\nResult:\n\n```php\n$data = [\n    0 =\u003e \"bbb\",\n    1 =\u003e \"eee\",\n    2 =\u003e \"hhh\"\n];\n```\n\n#### Get Specific Columns (Version 1.5.4+)\n\nTo extract multiple columns:\n\n```php\n\u003c?php\nuse buibr\\csvhelper\\CsvParser;\n\n$data = (new CsvParser('path/to/file'))-\u003etoColumns(['email', 'phone']);\n?\u003e\n```\n\nResult:\n\n```php\n$data = [\n    0 =\u003e [\"bbb\", \"ccc\"],\n    1 =\u003e [\"eee\", \"fff\"],\n    2 =\u003e [\"hhh\", \"iii\"]\n];\n```\n\n### Accessing Data\n\n#### Get the First Element\n\n```php\n\u003c?php\nuse buibr\\csvhelper\\CsvParser;\n\n$csv    = new CsvParser('path/to/file');\n$first  = $csv-\u003ecurrent();\n```\n\nResult:\n\n```php\nArray\n(\n    [0] =\u003e John\n    [1] =\u003e Doe\n    [2] =\u003e johndoe@test.test\n    [3] =\u003e 003344003203\n    [4] =\u003e Unknown\n)\n```\n\n#### Get Associative Array\n\n```php\n\u003c?php\nuse buibr\\csvhelper\\CsvParser;\n\n$assoc  = $csv-\u003ecurrent(true);\n```\n\nResult:\n\n```php\nArray\n(\n    [Firstname] =\u003e John\n    [Lastname] =\u003e Doe\n    [Email] =\u003e johndoe@test.test\n    [Phone] =\u003e 003344003203\n    [Adress] =\u003e Unknown\n)\n```\n\n#### Iterate Through CSV Records\n\n```php\n\u003c?php\nuse buibr\\csvhelper\\CsvParser;\n\n$csv = new CsvParser('path/to/file');\n\nwhile ($csv-\u003evalid()) {\n    // Get item as array\n    $item = $csv-\u003ecurrent(true);\n\n    // Get the value of the 'Firstname' column from the current record\n    $name = $csv-\u003ecolumn('Firstname');\n\n    // Get some of the columns\n    $fullname = implode(' ', $csv-\u003ecolumns(['Firstname', 'Lastname']));\n\n    $csv-\u003enext();\n}\n```\n\n## For More Use Cases\n\nExplore the `test` folder in this repository to see additional examples and use cases.\n\n---\n\nThis README provides a detailed guide on installing and using the CSV Helper. If you encounter any issues or have questions, feel free to open an issue on the GitHub repository.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbuibr%2Fcsv-helper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbuibr%2Fcsv-helper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbuibr%2Fcsv-helper/lists"}