I want to create a form with a country drop down list so I can just google and get all the countries but the question should I just encode it statically or generate dynamically with PHP. (Note it doesn't have to be necessary country list just any static list with lots of data)
<select> <option value="AF">Afghanistan</option> <option value="AX">Åland Islands</option> <option value="AL">Albania</option> ... </select>
or use php array i.e.
$countries = array ( 'AF' => 'Afghanistan', 'AX' => 'Åland Islands', 'AL' => 'Albania', ... );
and generate html
<!--Method 1--> <select> <?php foreach($countries as $id => $country) echo "<option value='$id'>$country</option>\n" ?> </select>
Also which method of generating is preferred or is more readable?
<!--Method 2--> <select> <?php foreach($countries as $id => $country):?> <option value="<?php echo $id; ?>"><?php echo $country; ?></option> <?php endforeach; ?> </select>
And finally should I escape variables with
htmlspecialchars even though I know the output will be valid?