Page 1 of 1
print from A to Z
Posted: Mon Jul 15, 2002 6:47 am
by xexexexe
hi! i'm beginner at php... and i have a question: what should I do if I want that php print letters from A to Z?

for ex. in turbo pascal it's written like this:
for c:= 'A' to 'Z' do
writeln(c);
Posted: Mon Jul 15, 2002 7:04 am
by samscripts
Several options:
Code: Select all
$letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
for( $i = 0; $i < 26; $i++) echo $lettersї$i];
or:
Code: Select all
$A = ord("A");
$Z = $A + 25;
for( $i = $A; $i <= $Z; $i++) echo chr($i);
check out:
http://www.php.net/ord
http://www.php.net/chr
http://www.php.net/strings
http://www.php.net/for
hope this helps, Sam
Posted: Mon Jul 15, 2002 7:41 am
by twigletmac
Another option is:
Code: Select all
<?php
for ($i = 'A'; $i != 'AA'; $i++) {
echo $i;
}
?>
Mac
Posted: Mon Jul 15, 2002 12:59 pm
by gnu2php
You could also do this:
Code: Select all
for ($x = 0; $x < 26; $x++)
{
print chr($x + ord('A'))."\n";
}