- Instant help with your Php coding problems

Process CSV line in PHP

Question:
How to process CSV line in PHP?
Answer:
$csvLine = 'Jane Doe,25,jane.doe@example.com,New York';
$fields = explode(',', $csvLine);

print_r($fields);
// Array ( [0] => Jane Doe [1] => 25 [2] => jane.doe@example.com [3] => New York )
Description:

When you are trying to process a CSV file in PHP, you basically have to split a string along a delimiter character. PHP has a built-in function called explode that can be used to do just that. The explode function chops up the given string along the boundaries defined by the delimiter character.

 

Share "How to process CSV line in PHP?"
Interesting things
ChatGPT in a nutshell