« Back to home

PHP's str_getcsv is Completely Broken

Posted on

Say you have a csv file that you want to parse with PHP. No problem, PHP has a function for everything! Assuming that maybe we’re on the beginner-to-medium level of experience, we might be tempted to reach for str_getcsv as a quick way to read CSV files.

Before we get started, I’m using PHP 7.3.14 on Ubuntu 18.04.3 LTS (Bionic Beaver).

Attempt #1

Let’s start with a simple CSV file:

name,age,phone,city
Bob,44,5555555,Boston
Jane,36,5555556,Philadelphia
Paco,54,5555557,Denver …

Read more »