Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7416755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:33:40+00:00 2026-05-29T07:33:40+00:00

I’m working on something which requires unique ID numbers which are in the format

  • 0

I’m working on something which requires unique ID numbers which are in the format of:

[A-Z][A-Z0-9][A-Z0-9][A-Z0-9][A-Z0-9][A-Z0-9]

And increment as:

AAAAAA, AAAAAB, … AAAAAZ, AAAAA0, AAAAA1, .. AAAAA9, AAAABA, AAAABB

I know I can increment letters in PHP, but how would I do letters and numbers in such a way?

Special note, baseconvert isn’t an option, because it must always be exactly 6 characters and fit the noted format incrementally. Further, baseconvert starts at 0, not A, so if I do start at “621937810” (AAAAAA) the next jump will be after AAAAAZ and on to AAAAB0. It seemed like the quickest solution, but it doesn’t work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T07:33:41+00:00Added an answer on May 29, 2026 at 7:33 am

    you could try base_convert from 36 to 10, increment then 10 to 36. I didn’t have any trouble with the larger numbers like ZZZZZW+1, however as it says in the php manual, there could be problems with larger numbers due to float/double precision.

    <?php
    echo "<pre>";
    //orig string
    $test = 'ZZZZZW';
    
    //convert from base36 to number.
    $test = base_convert($test, 36, 10);
    var_dump($test);
    
    //increment
    $test++;
    var_dump($test);
    
    //convert back (and upper case)
    $test = strtoupper(base_convert($test, 10, 36));
    var_dump($test);
    ?>
    

    outputs:

    string(6) "ZZZZZW"
    string(10) "2176782332"
    float(2176782333)
    string(6) "ZZZZZX"
    

    example can be see here

    Other than that, you can do some custom increment or even check out the base_convert comments in the php manual on converting some larger bases and values.

    Edit after clarification:

    Taken from the php comments page:

    <?php
    function intToAlphaBaseN($n,$baseArray) {
        $l=count($baseArray);
        $s = '';
        for ($i = 1; $n >= 0 && $i < 10; $i++) {
            $s =  $baseArray[($n % pow($l, $i) / pow($l, $i - 1))].$s;
            $n -= pow($l, $i);
        }
        return $s;
    }
    
    $base=array_merge(range('A','Z'), range(0,9));
    $zero = $base[0];
    
    //an integer number
    $r=rand(0, 999999);
    echo "$r converts to :".str_pad(intToAlphaBaseN($r,$base), 6, $zero, STR_PAD_LEFT)."\n";
    //an integer number
    $r++;
    echo "$r converts to :".str_pad(intToAlphaBaseN($r,$base), 6, $zero, STR_PAD_LEFT)."\n";
    //an integer number
    $r++;
    echo "$r converts to :".str_pad(intToAlphaBaseN($r,$base), 6, $zero, STR_PAD_LEFT)."\n";
    ?>
    

    working example

    As for incrementing from the string ID, I would suggest either saving the integer value, increment that and convert or write a similar function to convert to integer, increment, convert back. The former probably being easier.

    And as far as forcing the same 6 character format, the only time this should be a problem is when you pass the Z99999 which according to your format, is the max.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.