#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2006
    Posts
    21
    Rep Power
    0

    Replace 1 with A and A with 1


    I have a dynamic number of "rows".

    I want to replace the numbering of each row to be A, B , C etc etc.

    So how can I change 1 to be A, 26 to be Z and visa versa.

    To complicate things, how can I do 27 = AA?
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2006
    Posts
    21
    Rep Power
    0
    I've got this for number to alpha, just need to the return function now.

    PHP Code:
    function getNameFromNumber($num) {
        
    $numeric = ($num 1) % 26;
        
    $letter chr(65 $numeric);
        
    $num2 intval(($num 1) / 26);
        if (
    $num2 0) {
            return 
    getNameFromNumber($num2) . $letter;
        } else {
            return 
    $letter;
        }

  4. #3
  5. Headless Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,931
    Rep Power
    9647
    It would be easier to not use a function for this.
    PHP Code:
    $row "Y";
    $row++;
    echo 
    $row// Z
    $row++;
    echo 
    $row// AA 

IMN logo majestic logo threadwatch logo seochat tools logo