php alphabet output

aw thanks to miki for the tip. i was wondering if there was a smarter way to print out the alphebat 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.


5 Comments Leave a Comment

Shu [ Quote ]

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

for ($i=65; $i

July 6th, 2005 at 6:08 pm
Bubs [ Quote ]

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

July 6th, 2005 at 8:46 pm
David [ Quote ]

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

Note that you can’t say $i

August 8th, 2005 at 11:33 pm
Cine [ Quote ]

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

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

August 19th, 2005 at 6:41 am
kev [ Quote ]

thank you! Googled this and found it here!

Cine on 8/19/2005 at 6:41 am said:

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

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

Cheers!

K

July 26th, 2008 at 3:07 pm

Leave a Comment Name, email and comment are required.
Email will never be displayed.

Leave a Comment
  1. :biggrin: :blank: :blush: :bored: :confused: :cool: :down: :evil: :frown: :grin: :grr: :laidback: :left: :mad: :right: :sad: :secret: :shock: :smile: :stress: :tongue: :up: :wink: :yawn: :cute: :dead: :film: :floppy: :glasses: :grumpy: :headphones: :heart: :lightbulb: :ouch: :tv: :upsidedown: :vodka: :yell: :yuck: :yummy: