Pure-Essence.Net

php alphabet output

Posted by: pureessence on: July 6, 2005

aw thanks to miki for the tip. i was wondering if there was a smarter way to print out the alphabet in php than just typing them out LOL

Every letter of the English alphabet corresponds to an ASCII code, so rather than manually typing everything out, you can achieve the same result with a simple PHP loop.

The code below will output all uppercase letter from A to Z by running through ASCII codes 65-90 (the values for uppercase letters) and converting each code to its corresponding letter using the in-built PHP function chr().

<?php 
for ($i=65; $i< =90; $i++) { 
$x = chr($i); print $x; 
} 
?>

For lowercase letters, use the numbers 97-122 instead.

Advertisement

9 Responses to "php alphabet output"

It’s pretty cool, huh! I wish it could be done in less than 4 lines, though…

for ($i=65; $i

I have the acsii table for the uppercase letters memorized since my shift and caps lock keys no longer work… :P

A better solution is:
for ($i=”a”; $i != “aa”; $i++) print “$i\n”;

Note that you can’t say $i

$range = range(‘a’, ‘z’);
foreach($range as $a){
echo $a;
}

Shouldn’t that work too? Haven’t tried it, though. :)

thank you! Googled this and found it here!

[Comment ID #18794 Will Be Quoted Here]

Cheers!

K

Thanks all,

This entry is useful!

This code works well. Thanks a ton for your code, it helped a bunch. :)

Genius! Thanks for the help!

i also dig using a foreach range() for this. good article.

Leave a Reply

Fill in your details below or click an icon to log in:

Gravatar
WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

My most adorable Pomeranians

Categories

Archives

SocialVibe


Follow

Get every new post delivered to your Inbox.