how can I modify my function to make use of
<select name="extra2" id="extra2" class="select_smaller">
<option value="Algema">Algema</option>
<option value="Barkas">Barkas</option>
.
.
.
</select>
that I have on my forms and then creates the array input of the function below to get it work ?
$options = array('Algema', 'Barkas', 'Cadillac', …);
If this is not possible or a big thing, we can avoid the “get from dropdown list and create me an array input” and
just use the dropdown list as is, to produce my desired output.
The result is correct, the code works great but what I want is to avoid the copy-paste around 200 different dropdown lists with about 10 options each. Instead I will use a program for mass text input to paste the code in the front and end of the lists.
function makeSelect($name, $options) {
foreach ($options as &$option) {
$selected = isset($_GET[$name]) && $_GET[$name] == $option;
$option = sprintf('<option value="%1$s"%2$s>%1$s</option>',
htmlspecialchars($option),
$selected ? ' selected="selected"' : null);
}
return sprintf('<select name="%1$s" id="%1$s" class="select">%2$s</select>',
htmlspecialchars($name),
join($options));
}
$options = array('Algema', 'Barkas', 'Cadillac', …);
// instead of array I prefer to use here something $options=the dropdown list as is.
echo makeSelect('car', $options);
Use regular expressions, for example (assuming
$list_htmlcontains HTML in the form you have cited):This has been tested. If you assign value in the following way:
and do
print_r($found_values), the result will be:And that means, you get proper values for each option in array. Assuming of course, that these values contain small letters, big letters or ciphers, but nothing more (otherwise the regular expression has to be adjusted to meet your needs).
EDIT:
For your convenience, the same thing in form of a function:
Now it should be ok to do it in the following way:
EDIT 2:
The same mechanism included within your function could look like that: