|
Create Alphabet Links With PHPPosted: Feb 3, 2011 Last modified: Apr 27, 2018When a site has many sections or pages for a category, it can be useful to separate all entries by what letter of the alphabet their initial falls under. For example, you may want to do this in a directory site. It is a simple matter to create 26 HTML for ($i = 65; $i <= 90; $i++) {
printf('<a href="%1$s.html" class="myclass">%1$s</a> ', chr($i));
}
The code loops from 65 to 90 because that is the range of integers that defines the upper case English alphabet in ASCII codes. The function The drawback to using this method to create links is that it isn't as fast to load as hard-coded HTML links (though in many cases the difference will be minute, you probably want to optimize your site anyway). You could always use the above snippet to make generating the links easier and then place the output in an HTML file for speedier downloads. See Ascii Table for a list of all ASCII codes and their corresponding characters and symbols. |