Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Nov 2007
    Posts
    144
    Thanks
    64
    Thanked 0 Times in 0 Posts

    Increment string "a" so it says "b" ??

    Hi,

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

    $str 
    "a";

    echo 
    $str;

    echo 
    $str +1;

    ?>
    It shows "a1"

  • #2
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    you probably want the chr() function (http://php.net/chr):
    PHP Code:
    <?php

    $a 
    97//65 for caps
    for($i $a$i $a 26$i++) {
      echo 
    chr($i);
    }
    My thoughts on some things: http://codemeetsmusic.com
    And my scrapbook of cool things: http://gjones.tumblr.com

  • #3
    Regular Coder ralph l mayo's Avatar
    Join Date
    Nov 2005
    Posts
    951
    Thanks
    1
    Thanked 31 Times in 29 Posts
    you can use ++$str to increment the last letter.
    It even carries correctly: ++"xyz" == "xza"

  • #4
    Regular Coder
    Join Date
    Nov 2007
    Posts
    144
    Thanks
    64
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by ralph l mayo View Post
    you can use ++$str to increment the last letter.
    Fantastic!!! Thanks very much!

  • #5
    Regular Coder
    Join Date
    Nov 2007
    Posts
    144
    Thanks
    64
    Thanked 0 Times in 0 Posts
    Done!
    PHP Code:
    for ($letter "a"$letter != "aa" ;++$letter) {
    echo 
    $letter;



  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •