Jump to content

[SOLVED] Createing 'next id' in alphanumerical format,


tym

Recommended Posts

Hi

 

I'd like to make a script that will use tracking url to my purposes.

 

In this url i'm allowed to use only alpha numerical signs,

in part of this url, there are 3 character long,  id of my keyword.

 

this might look like 001, 00Z, or 09Z

where Z is last letter allowed.

I want to create next ID out of old one.

ex.

A9Z turns into B00. and B00 turns into B01

 

if there would be two characters then it would be easy for me - just

typing all combination (a think 5) but when it comes to 3 characters

i think there would be too many ifs

 

so

 

How  i can do it?

 

 

 

I think you could solve it like this I'm not gonna write the script for you since that wouldnt be any fun  ;).

 

 

1. split the input into an array so that each character has its own array

for example

$string="0XY";

//now you need each character in its own array
$splittedString[0]="0";
$splittedString[1]="X";
$splittedString[2]="Y";

 

now you need to convert each character to a number for the first character the range would be 0 to 36

the rest you will have to figure out but basicly what you want is a function that converts your character set to a number and a number to the character set good luck

 

 

 

 

 

 

If the order is 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z for every character, then it could be done using base_convert(). For example:

 

$id             = "a9z";
$id_decimal = base_convert($id, 36, 10);
$id_next      = base_convert($id_decimal+1, 10, 36);

 

Or something like that.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.