Just use the values of the existing site...

Jun 16, 2008

The problem: you need to turn the values of an HTML select element into a PHP array, and you don't want to do it by hand because it has a lot of entries.

The solution: regular expressions! (using Eclipse's regex search/replace).

  1. Copy the HTML code of the select element whose values you want to get.
  2. In eclipse, paste the code in your PHP file.
  3. Press Ctrl+F to open the find/replace window.
  4. Click the "Regular expressions" checkbox.
  5. Find: (.*)
  6. Replace: '$1' => '$2',
  7. Click "Replace All".
  8. Manually replace the opening and closing tags with array( and );