{"id":23346150,"url":"https://github.com/tpmanc/csv-helper","last_synced_at":"2025-04-07T17:19:07.782Z","repository":{"id":57072274,"uuid":"43750663","full_name":"tpmanc/csv-helper","owner":"tpmanc","description":"Helper for csv files","archived":false,"fork":false,"pushed_at":"2016-11-30T14:08:48.000Z","size":13,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-15T00:08:20.493Z","etag":null,"topics":["csv","csv-files","php"],"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/tpmanc.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":"2015-10-06T12:57:42.000Z","updated_at":"2018-07-17T11:48:50.000Z","dependencies_parsed_at":"2022-08-24T10:40:53.743Z","dependency_job_id":null,"html_url":"https://github.com/tpmanc/csv-helper","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tpmanc%2Fcsv-helper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tpmanc%2Fcsv-helper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tpmanc%2Fcsv-helper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tpmanc%2Fcsv-helper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tpmanc","download_url":"https://codeload.github.com/tpmanc/csv-helper/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247694881,"owners_count":20980733,"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-files","php"],"created_at":"2024-12-21T07:12:55.417Z","updated_at":"2025-04-07T17:19:07.750Z","avatar_url":"https://github.com/tpmanc.png","language":"PHP","readme":"# CSV Helper\nHelper class for working with CSV files.\n\n## Install via Composer\n\nRun the following command\n\n```bash\n$ composer require tpmanc/csvhelper \"*\"\n```\n\nor add\n\n```bash\n$ \"tpmanc/csvhelper\": \"*\"\n```\n\nto the require section of your `composer.json` file.\n\n## File reading\n\nfile.csv:\n```\nRussia;Moscow;\nFrance;Paris;\nGreat Gritain;London;\n```\n\n```php\nuse tpmanc\\csvhelper\\CsvHelper;\n\n...\n\nCsvHelper::open('files/file.csv')-\u003eparse(function($line) {\n    echo $line[0] . ': ' . $line[1];\n});\n```\n\nResult:\n```\nRussia: Moscow\nFrance: Paris\nGreat Gritain: London\n```\n\n### Custom delimiter\n\nfile.csv:\n```\nRussia|Moscow|\nFrance|Paris|\nGreat Gritain|London|\n```\n\n```php\nuse tpmanc\\csvhelper\\CsvHelper;\n\n...\n\nCsvHelper::open('files/file.csv')-\u003edelimiter('|')-\u003eparse(function($line) {\n    echo $line[0] . ': ' . $line[1];\n});\n```\n\nResult:\n```\nRussia: Moscow\nFrance: Paris\nGreat Gritain: London\n```\n\n### Change encoding\n\n```php\nuse tpmanc\\csvhelper\\CsvHelper;\n\n...\n\nCsvHelper::open('files/file.csv')-\u003eencode('cp1251', 'utf-8')-\u003eparse(function($line) {\n    echo $line[0] . ': ' . $line[1];\n});\n```\n\n### Offset and limit\n\nfile.csv:\n```\nRussia;Moscow;\nFrance;Paris;\nGreat Gritain;London;\n```\n\n```php\nuse tpmanc\\csvhelper\\CsvHelper;\n\n...\n\nCsvHelper::open('files/file.csv')-\u003eoffset(1)-\u003elimit(1)-\u003eparse(function($line) {\n    echo $line[0] . ': ' . $line[1];\n});\n```\n\nResult:\n```\nFrance: Paris\n```\n\n### Using variables from the parent scope\n\nfile.csv:\n```\nRussia;Moscow;\nFrance;Paris;\nGreat Gritain;London;\n```\n\n```php\nuse tpmanc\\csvhelper\\CsvHelper;\n\n...\n\n$lineCount = 0;\n$array = [];\nCsvHelper::open('files/file.csv')-\u003eparse(function($line) use(\u0026$lineCount, \u0026$array) {\n    $lineCount++;\n    $array[] = $line[0];\n});\necho $lineCount;\necho $array[0];\necho $array[1];\n```\n\nResult:\n```\n3\nRussia\nFrance\n```\n\n## Create new file\n\n```php\nuse tpmanc\\csvhelper\\CsvHelper;\n\n...\n\n$file = CsvHelper::create()-\u003edelimiter(';');\n\n$file-\u003eencode('cp1251', 'utf-8'); // change encoding\n$file-\u003eaddLine('1.;France;'); // add row to file by string\n$file-\u003eaddLine([\n    2,\n    'Germany'\n]); // add row to file by array\n\n$file-\u003esave('./new-file.csv');\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftpmanc%2Fcsv-helper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftpmanc%2Fcsv-helper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftpmanc%2Fcsv-helper/lists"}