Using EditPlus to create a PHP Array from a list of values

By using editors that support regular expressions you can easily transform a list of values or options into a PHP array that later will allow you to create more complex things like options on a <select> tag.

1. Get the list of values

Once you have the list of values, it will show something like this:

2. Replace each line

To replace each line between quotes, we can use the following regular expression:

Find: ^(.*)
Replace With: "\1",

image

3. Complete the beginning and end of the array

To complete the beginning and end of the array just need to use the PHP array format assigning it to a variable.

$list = array(
"Agiortiko",
"Aglianico",
"Airen",
"Albana",
"Albarinho",
"Albarinyo",
"Albillo",
"Alfrocheiro Preto",
"Aligote",
"Aragonez",
"Arinto",
"Arneis",
"Assyrtiko",
"Auxerois",
"Baboso negro",
"Bacchus",
"Baga");

Then, $list is ready to be used in your application with the list of values.

Advertisement

Did you like it?

No comments yet.

Leave a Comment