SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Guru kgtrip's Avatar
    Join Date
    Jun 2003
    Location
    Karplakistan
    Posts
    804
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    substruct 1 from a char?

    hi people

    little question,
    $a="a";
    $a++; will result in $a=b

    now I want to do the opposite
    $a--; but it gives the same letter

    what am I doing wrong?

    cheers
    Kgtrip

  2. #2
    My precious!!! astericks's Avatar
    Join Date
    Mar 2002
    Location
    Vancouver, BC
    Posts
    1,971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you can only do ++ and -- do integers, not strings.

    were you looking for chr ?

  3. #3
    SitePoint Guru kgtrip's Avatar
    Join Date
    Jun 2003
    Location
    Karplakistan
    Posts
    804
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    still how can I move forward and backward in the char values???

  4. #4
    PHP manual bot bronze trophy Gaheris's Avatar
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,195
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    48 to 57 in chr 0 - 9
    65 to 90 in chr A - Z
    97 to 122 in chr a - z

  5. #5
    SitePoint Addict jtresidder's Avatar
    Join Date
    Nov 2003
    Location
    Southampton, UK
    Posts
    346
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kgtrip
    still how can I move forward and backward in the char values???
    PHP Code:
    $char 'a';
     
    // to add one, use:
    $char chr(ord($char)+1);
     
    // to subtract one, use:
    $char chr(ord($char)-1); 
    Bear in mind you'll probably want to error-check to catch the ends of the alphabet. Gaheris listed the ascii numbers that the ord function will return for the various characters.

  6. #6
    SitePoint Guru kgtrip's Avatar
    Join Date
    Jun 2003
    Location
    Karplakistan
    Posts
    804
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK
    that seems ok I'll check it out


    Thank's guys


Bookmarks

Posting Permissions

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