Small, short code snippets that other people may find useful. Do you have a good regex that you would like to share? Share it! Even better, the code can be commented on, and improved.
<?php
$opt = array(
'opt1' => 'This is the option #1',
'opt2' => 'This is the option #2',
'opt3' => 'This is the option #3',
'opt4' => 'This is the option #4',
'opt5' => 'This is the option #5'
);
echo "Just print the options tags in case the select tag is already present:\n";
echo printSelect($opt), "\n";
echo "Print the select tag and the options tag inside it:\n";
echo printSelect($opt, 'options'), "\n";
echo "Now we say which option is selected by default:\n";
next($opt);
echo printSelect($opt, 'options', key($opt)), "\n";
echo "Now take the form information to tell which option is default, and also an additional attribute (onChange for a jump menu):\n";
next($opt);
$_POST['options'] = key($opt);
echo printSelect($opt, 'options', $_POST['options'], 'onChange="javascript:document.form1.submit();"'), "\n";
?>
Just print the options tags in case the select tag is already present:
<option label="opt1" value="opt1">&nbsp;This is the option #1&nbsp;</option>
<option label="opt2" value="opt2">&nbsp;This is the option #2&nbsp;</option>
<option label="opt3" value="opt3">&nbsp;This is the option #3&nbsp;</option>
<option label="opt4" value="opt4">&nbsp;This is the option #4&nbsp;</option>
<option label="opt5" value="opt5">&nbsp;This is the option #5&nbsp;</option>
Print the select tag and the options tag inside it:
<select name="options" >
<option label="opt1" value="opt1">&nbsp;This is the option #1&nbsp;</option>
<option label="opt2" value="opt2">&nbsp;This is the option #2&nbsp;</option>
<option label="opt3" value="opt3">&nbsp;This is the option #3&nbsp;</option>
<option label="opt4" value="opt4">&nbsp;This is the option #4&nbsp;</option>
<option label="opt5" value="opt5">&nbsp;This is the option #5&nbsp;</option>
</select>
Now we say which option is selected by default:
<select name="options" >
<option label="opt1" value="opt1" selected>&nbsp;This is the option #1&nbsp;</option>
<option label="opt2" value="opt2">&nbsp;This is the option #2&nbsp;</option>
<option label="opt3" value="opt3">&nbsp;This is the option #3&nbsp;</option>
<option label="opt4" value="opt4">&nbsp;This is the option #4&nbsp;</option>
<option label="opt5" value="opt5">&nbsp;This is the option #5&nbsp;</option>
</select>
Now take the form information to tell which option is default, and also an additional attribute (onChange for a jump menu):
<select name="options" onChange="javascript:document.form1.submit();">
<option label="opt1" value="opt1">&nbsp;This is the option #1&nbsp;</option>
<option label="opt2" value="opt2" selected>&nbsp;This is the option #2&nbsp;</option>
<option label="opt3" value="opt3">&nbsp;This is the option #3&nbsp;</option>
<option label="opt4" value="opt4">&nbsp;This is the option #4&nbsp;</option>
<option label="opt5" value="opt5">&nbsp;This is the option #5&nbsp;</option>
</select>