...

View Full Version : Increment string "a" so it says "b" ??



samuurai
12-19-2007, 06:22 PM
Hi,

How do I programatically make an alphabet?
This, of course doesn't work because it's a string.


<?php

$str = "a";

echo $str;

echo $str +1;

?>

It shows "a1"

GJay
12-19-2007, 07:09 PM
you probably want the chr() function (http://php.net/chr):


<?php

$a = 97; //65 for caps
for($i = $a; $i < $a + 26; $i++) {
echo chr($i);
}

ralph l mayo
12-19-2007, 07:14 PM
you can use ++$str to increment the last letter.
It even carries correctly: ++"xyz" == "xza"

samuurai
12-19-2007, 08:15 PM
you can use ++$str to increment the last letter.
Fantastic!!! Thanks very much!

samuurai
12-28-2007, 07:22 PM
Done!


for ($letter = "a"; $letter != "aa" ;++$letter) {
echo $letter;
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum