Zend - The PHP Company




Menus & Navigation

Add Code


Word link navigation  

Type: code fragment
Added by: atur
Entered: 07/06/2003
Last modified: 09/12/2002
Rating: - (fewer than 3 votes)
Views: 4847
Build from a word list, html links from the first letter of this words.


<?php

// Build letter link function
//
function & build_link(&$word)
{
    static 
$prev_letter;

    
// Extract the first letter
    
$first_letter substr($word,0,1);

    
// Build a link for this letter if this letter wasn't extracted before, 
    //
    
if($prev_letter != $first_letter)
    {
       
$prev_letter $first_letter;
       
       
// Modify the url to your needs
       //
       
return ' [<a href="letter_'.$prev_letter.'.htm">'.strtoupper($prev_letter).'</a>] ';
    }
    else
    {
       return 
false;
    }
}

// The word list array.
//
$word_list = array(
    
'affect',    
    
'courtesy',
    
'cult',    
    
'despair',
    
'feudal',
    
'file',
    
'analogy',
    
'mass',
    
'delay',
    
'patrol');

// Sort the word list. This is necessairy to get unique links
//
sort($word_list);

// Build letters links of the word list
//
foreach($word_list as $word)
{
    
$link build_link($word);
    
    if(
$link)
    {
        echo 
$link;
    }
}
?>


Usage Example




Rate This Script





Search



This Category All Categories