{"id":20312494,"url":"https://github.com/belguinan/csv-simple-reader","last_synced_at":"2026-02-03T20:06:27.774Z","repository":{"id":62492894,"uuid":"235687442","full_name":"belguinan/csv-simple-reader","owner":"belguinan","description":"Simple PHP class for CSV manipulation. \"with no dependencies\"","archived":false,"fork":false,"pushed_at":"2024-10-30T02:39:01.000Z","size":20,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-15T16:02:47.922Z","etag":null,"topics":["csv","csv-export","csv-import","csv-reader","php","php5"],"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/belguinan.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-01-22T23:20:47.000Z","updated_at":"2024-10-30T02:45:41.000Z","dependencies_parsed_at":"2025-04-11T16:53:45.375Z","dependency_job_id":"dcb33794-10da-4caa-a72e-51d3c542f457","html_url":"https://github.com/belguinan/csv-simple-reader","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/belguinan/csv-simple-reader","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/belguinan%2Fcsv-simple-reader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/belguinan%2Fcsv-simple-reader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/belguinan%2Fcsv-simple-reader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/belguinan%2Fcsv-simple-reader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/belguinan","download_url":"https://codeload.github.com/belguinan/csv-simple-reader/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/belguinan%2Fcsv-simple-reader/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29055653,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-03T15:43:47.601Z","status":"ssl_error","status_checked_at":"2026-02-03T15:43:46.709Z","response_time":96,"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":["csv","csv-export","csv-import","csv-reader","php","php5"],"created_at":"2024-11-14T18:06:22.832Z","updated_at":"2026-02-03T20:06:27.758Z","avatar_url":"https://github.com/belguinan.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CSV Simple Reader\n\nA lightweight, zero-dependency PHP library for reading, writing, and exporting CSV files. Works with PHP 5.4 and above.\n\n[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)\n\n## Features\n\n- 🚀 Simple and intuitive API\n- 📖 Memory-efficient reading of large files\n- 💾 Export data to CSV files\n- ⬇️ Direct CSV downloads\n- 🔒 Secure file handling\n- 0️⃣ Zero dependencies\n- ✅ PHP 5.4+ compatible\n\n## Installation\n\nInstall via Composer:\n\n```bash\ncomposer require belguinan/csv-simple-reader\n```\n\n## Quick Start\n\n```php\nuse Belguinan\\CsvExporter;\n\n// Initialize\n$csv = new CsvExporter();\n\n// Read CSV file\nforeach ($csv-\u003ereadFrom('path/to/file.csv') as $row) {\n    var_dump($row);\n}\n```\n\n## Usage Guide\n\n### Reading CSV Files\n\n```php\n$csv = new CsvExporter();\n\n// Read file line by line (memory efficient)\nforeach ($csv-\u003ereadFrom('input.csv') as $row) {\n    // $row is an array containing the CSV columns\n    var_dump($row);\n}\n```\n\n### Creating CSV Files\n\n```php\n// Your data as array\n$data = array(\n    array('John', 'Doe', 'john@example.com'),\n    array('Jane', 'Smith', 'jane@example.com')\n);\n\n// Optional headers\n$headers = array('First Name', 'Last Name', 'Email');\n\n// Create CSV exporter\n$csv = new CsvExporter($data, $headers);\n\n// Process and save\n$csv-\u003eprocess()-\u003esave('output.csv');\n```\n\n### Downloading CSV Files\n\n```php\n// Create and force download\n$csv = new CsvExporter($data, $headers);\n$csv-\u003eprocess()-\u003edownload('users-export');\n```\n\n### Chaining Operations\n\n```php\n// Process, download, and save in one go\n$csv-\u003eprocess()\n    -\u003edownload('export-file')\n    -\u003esave('backup/export.csv');\n```\n\n## Error Handling\n\nThe library throws `Exception` for various error conditions. It's recommended to wrap operations in try-catch blocks:\n\n```php\ntry {\n    $csv = new CsvExporter($data);\n    $csv-\u003eprocess()-\u003esave('output.csv');\n} catch (\\Exception $e) {\n    echo \"Error: \" . $e-\u003egetMessage();\n}\n```\n\n## Common Exceptions\n\n- File not found\n- File not readable\n- Directory not writable\n- Invalid CSV data structure\n- Memory stream errors\n\n## Best Practices\n\n1. **Reading Large Files**\n   ```php\n   // Good - Memory efficient\n   foreach ($csv-\u003ereadFrom('large.csv') as $row) {\n       processRow($row);\n   }\n   ```\n\n2. **Setting Headers**\n   ```php\n   // Explicit headers\n   $headers = array('ID', 'Name', 'Email');\n   $csv = new CsvExporter($data, $headers);\n\n   // Auto-generated headers from data keys\n   $csv = new CsvExporter($data);\n   ```\n\n3. **Error Handling**\n   ```php\n   try {\n       $csv-\u003ereadFrom('file.csv');\n   } catch (\\Exception $e) {\n       log_error($e-\u003egetMessage());\n       // Handle error appropriately\n   }\n   ```\n\n## Examples\n\n### Export Users Table\n\n```php\n// Fetch users from database\n$users = $db-\u003equery('SELECT id, name, email FROM users');\n\n// Convert to array\n$data = array();\nwhile ($row = $users-\u003efetch_assoc()) {\n    $data[] = $row;\n}\n\n// Export\n$csv = new CsvExporter($data);\n$csv-\u003eprocess()-\u003edownload('users-export');\n```\n\n### Process CSV in Chunks\n\n```php\n$csv = new CsvExporter();\n$chunk = array();\n\nforeach ($csv-\u003ereadFrom('large-file.csv') as $index =\u003e $row) {\n    $chunk[] = $row;\n    \n    // Process in chunks of 1000\n    if (count($chunk) \u003e= 1000) {\n        processChunk($chunk);\n        $chunk = array();\n    }\n}\n\n// Process remaining rows\nif (!empty($chunk)) {\n    processChunk($chunk);\n}\n```\n\n## License\n\nMIT License - feel free to use this library in your projects.\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## Support\n\nFor bugs and feature requests, please use the [GitHub issue tracker](https://github.com/belguinan/csv-simple-reader/issues).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbelguinan%2Fcsv-simple-reader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbelguinan%2Fcsv-simple-reader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbelguinan%2Fcsv-simple-reader/lists"}