I have a comma-separated list that I want to import into the database, and in some cases the last item is empty:
item1, item2, item3
item1, item2,
item1, item2,
I would like to replace all these empty columns with a placeholder value using regexp
item1, item2, item3
item1, item2, PLACEHOLDER
item1, item2, PLACEHOLDER
I tried this:
preg_replace("/,\n/", ",PLACEHOLDER\n",$csv);
... but it does not work. Does anyone know which regular expression will work for this?
source
share