CSV‐Parse Info - thepoopooman652/proishs-webtools GitHub Wiki

csv-parse — CSV upload and preview

Overview

csv-parse provides a small web interface that accepts CSV or text files and renders them as an HTML table. The implementation includes server-side parsing with automatic delimiter detection and an option to treat the first row as a header row.

Files

  • index.php — Upload form and parser. Handles file uploads, uses fgetcsv() for parsing, detects common delimiters (comma, semicolon, tab), and produces an HTML table with escaped cell values.

Parsing rules and behavior

  • Delimiter detection: the parser examines the first non-empty line and chooses the delimiter with the largest number of fields among common candidates (, ; \t).
  • Header row: if the user selects the "first row is header" option, the first parsed row is used as column headers.
  • Normalization: rows with fewer columns than the header are padded with empty strings; rows with extra columns retain all columns and the table displays them.
  • Cell rendering: all cell values are escaped for HTML and long values are wrapped to avoid breaking the table layout.

Configuration knobs

  • Maximum upload size: a server-side limit may be enforced in index.php (the uploader checks $_FILES size). Adjust the php.ini upload_max_filesize and the local check in index.php as needed.
  • Accepted file extensions: the form restricts uploads to .csv and .txt by default; this behavior can be adjusted in the accept attribute or server-side checks.

Usage examples

  1. Simple upload via browser
  • Open index.php in a browser.
  • Select a file and (optionally) check "First row is header".
  • Submit and view the rendered table and a raw preview area.
  1. Direct POST with curl (multipart)
curl -F "uploadedFile=@/path/to/data.csv" http://localhost:8000/index.php

Performance and large files

  • The current implementation loads the uploaded file into PHP memory via streaming through fgetcsv(); for very large files consider implementing streaming pagination (read, render only N rows per request) or server-side chunked processing.

Testing and local run

Start a local PHP server in the csv-parse directory and test with representative CSV files:

cd 'C:\Users\Administrator\Documents\GitHub\proish-webtools\csv-parse'
php -S 127.0.0.1:8000 -t .

Open http://127.0.0.1:8000/index.php and test with sample CSVs (including edge cases: quoted fields, embedded newlines, semicolon-delimited files).

Changelog

  • 2025-11-06: Documented delimiter detection, normalization behavior, and usage examples.

Notes

This document focuses on the parser behavior, configuration, and how to exercise the tool programmatically. Integration notes for embedding the parser as a service are provided under the developer section of the main repository README.