1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Sorting the order in a textbox

Discussion in 'PHP' started by khalid, Dec 30, 2007.

  1. #1
    Anyone know how I can sort the order of the fonts alphabetically in the textbox on www.tattoolettering.net?

    Regards,

    Khalid.
     
    khalid, Dec 30, 2007 IP
  2. hogan_h

    hogan_h Peon

    Messages:
    199
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #2
    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.
     
    hogan_h, Dec 30, 2007 IP
  3. khalid

    khalid Active Member

    Messages:
    1,628
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    80
    #3
    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.
     
    khalid, Dec 30, 2007 IP
  4. hogan_h

    hogan_h Peon

    Messages:
    199
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #4
    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:
     
    hogan_h, Dec 30, 2007 IP
    khalid likes this.
  5. khalid

    khalid Active Member

    Messages:
    1,628
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    80
    #5
    Thank you ever so much, rep left buddy.

    Much appreciated.
     
    khalid, Dec 30, 2007 IP
    hogan_h likes this.
  6. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #6
    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:
     
    Barti1987, Dec 30, 2007 IP