Late last week, I was working on a project that was responsible for reading the contents of a CSV, parsing the information, and then inserting it into the WordPress database.
But I hit a snag (as we so often do, right?): The first few rows of the CSV were working fine, but a number of the rows were failing to import.
The thing is, there appeared to be no rhyme or reason. I made sure the CSV was a raw text file and even saved a new version of the file using a raw editor twice to make sure any, um, ‘stray’ characters were being removed.
Unfortunately, it didn’t work so rather than spend time trying to reformat the entire file, I ended up writing a small regex to strip hidden ASCII characters form the incoming information.