tym Posted April 24, 2008 Share Posted April 24, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/102762-solved-createing-next-id-in-alphanumerical-format/ Share on other sites More sharing options...
RichardRotterdam Posted April 24, 2008 Share Posted April 24, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/102762-solved-createing-next-id-in-alphanumerical-format/#findComment-526359 Share on other sites More sharing options...
craygo Posted April 24, 2008 Share Posted April 24, 2008 How is your code going to be?? Because the next code after A9Z should be AA0. That is if you order is like 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 Ray Quote Link to comment https://forums.phpfreaks.com/topic/102762-solved-createing-next-id-in-alphanumerical-format/#findComment-526373 Share on other sites More sharing options...
moselkady Posted April 24, 2008 Share Posted April 24, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/102762-solved-createing-next-id-in-alphanumerical-format/#findComment-526397 Share on other sites More sharing options...
craygo Posted April 24, 2008 Share Posted April 24, 2008 Beat me to it. <?php $url = "AZZ"; $next = base_convert($url, 36, 10)+1; $new = base_convert($next, 10, 36); echo $new; ?> Ray Quote Link to comment https://forums.phpfreaks.com/topic/102762-solved-createing-next-id-in-alphanumerical-format/#findComment-526423 Share on other sites More sharing options...
tym Posted April 25, 2008 Author Share Posted April 25, 2008 moselkady and Ray, wow!! Thank you very much:) I'll use it. Dj Kat- Thats how i started but for 3 letters and combination of ifs i run out of Brain CPU ) Quote Link to comment https://forums.phpfreaks.com/topic/102762-solved-createing-next-id-in-alphanumerical-format/#findComment-527121 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.