Niall McMahon

The ramblings and occasional intellect from a web developer, music lover and genealogist.

MENU

Code snippet: Print out A-Z in PHP

If you have ever wanted to printed out the alphabet without having to manually write out 26 of the same link, button, etc. use this handy PHP script:

		for($i=97; $i<123; $i++) {
			print(chr($i) . ' ');
		}

If you needed to print out links that might direct a user to a set of results for that letter, for example:

		for($i=97; $i<123; $i++) {
			print('<a href="results.php?letter='.chr($i).'">'.chr($i).'</a> ');
		}

To use uppercase letters instead of lowercase, replace the numbers in the for loop with 65 and 90.

Bookmark and Share
blog comments powered by Disqus