Convert CSV Headers into an PHP Array using Notepad++

A little handy note-to-self on how to get a CSV Row from Windows into a Hard-coded array in PHP. Yes, there’s methods to do this pragmatically, but if you’re wanting this for a Configuration file of some sorts… then I needed to do this 🙂 Notepad++ is my weapon of choice for it’s awesome extended abilities.

Say for example you have a long .csv header row as below:


sku,store_view_code,set_code,product_type,categories,product_websites,name

Now that’s only a few columns.. 65 more for Magneto imports (Which is what I’ve done this for!)

  1. Copy paste this into Notepad++
  2. Move the carat cursor to before the first line,Press Ctrl + F and select “Replace
  3. Select “Regular Expression” Under “Search Mode
  4. Find What: (\w+),
  5. Replace With: “$1” => “”,\r\n

Example Screenshot.

This will produce:

"sku" => "",
"store_view_code" => "",
"set_code" => "", 
"product_type" => "", 
"categories" => "", 
"product_websites" => "",
"name" => ""

This will then allow you to wrap the standard Array()!

array(
"sku" => "",
"store_view_code" => "",
"set_code" => "", 
"product_type" => "", 
"categories" => "", 
"product_websites" => "",
"name" => ""
);