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.
Reference:
PHP explode reference
Share "How to process CSV line in PHP?"
Related snippets:
- Remove whitespace from the beginning and end of a string in PHP
- Locate a substring within a string in PHP
- Process CSV line in PHP
- Extract a substring from a string in PHP
- Split a string into words in PHP
- Replace spaces with dashes in PHP
- Replace only the first occurrence of a string in PHP
- Replace last occurrence of a string in a string in PHP
- Remove all attributes from HTML tags in PHP
- Remove HTML tags from a string except p, b, i and br in PHP
- Remove HTML tags from a string in PHP
Tags:
csv, split, delimiter, string, line, text, array, php Technical term:
Process CSV line in PHP