* refactor: clean to roadmap content * refactor: move shared helpers into scripts/lib
890 B
890 B
CSV Processing
CSV processing refers to handling CSV (Comma Separated Values) files in PHP, an operation significantly useful for managing tabular data. PHP provides a few key functions to handle CSV files effectively. For example, fgetcsv() allows you to read CSV file line by line, fputcsv() lets you write line by line into a CSV file, and str_getcsv() allows you to parse a CSV string into an array. A quick example of reading a CSV file:
if (($handle = fopen("sample.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
print_r($data);
}
fclose($handle);
}
In this snippet, PHP reads through each line of the sample.csv file, converting each into an array with fgetcsv().
Visit the following resources to learn more: