Anyone know how I can sort the order of the fonts alphabetically in the textbox on www.tattoolettering.net? Regards, Khalid.
If the font elements are inside an array, call sort functions with that array as parameter. [sort($fonts) or asort($fonts)]. If they are not, then build an array and sort it, then you can output option elements in alphabetical order.
Hi hogan, thanks for your reply. i am a complete newbie, can you help me further here is the code for the texbox... Thanks in advance, Khalid.
Hi Khalid, here is the code from the top of my head, i didn't test it, consider it as "pseudo" code with no error handling: <select name="font" id="font" size="10" style="width:200px"> <? $fonts = Array(); // populate select box $font_directory_handle = opendir($config_dir . 'fonts/'); while (false !== ($font_file = readdir($font_directory_handle))) { if ($font_file != '.' && $font_file != '..') { $font = explode(".ttf",$font_file,2); $fonts[$font_file] = $font[0]; } } asort($fonts); foreach($fonts as $key => $value) { if ($key == 'Arial.ttf') { print ("<option selected value=\"".$key."\">".$value."</option>"); } else { print ("<option value=\"".$key."\">".$value."</option>"); } } ?> </select> PHP:
This should be faster: <select name="font" id="font" size="10" style="width:200px"> <? $font_list = glob("fonts/*.ttf") asort($font_list); foreach($font_list as $value){ $font_file = basename($value); $font_name = current(explode('.ttf',$value); if($font_file == 'Arial.ttf'){$sel=' selected';}else{$sel=NULL;} echo '<option value="'.$value.'"'.$sel.'>'.$font_name.'</option>'; } ?> </select> PHP: