guymclaren Posted September 17, 2008 Share Posted September 17, 2008 I have a need to create unique account numbers based on three letters and 3 numbers. I want to create a little script to check the surname. In ASP I can select the first three letters after the space eg Input "Guy McLaren" I want to select the MCL and then add 3 numbers to it. the first MCL would be 001 the next would be 002 etc. Is there an easy way to do this? Or would it be simpler for me to use the unique id created in the database as a UID? My initial thoughts are 1. find the space and select the letters 2. Check database for account numbers starting with MCL and check last number 3. seperate number from string 4. add one 5. join string Will that be the best way? Quote Link to comment https://forums.phpfreaks.com/topic/124699-unique-account-numbers/ Share on other sites More sharing options...
Maq Posted September 17, 2008 Share Posted September 17, 2008 Is there an easy way to do this? Or would it be simpler for me to use the unique id created in the database as a UID? DB UID would be much easier... Quote Link to comment https://forums.phpfreaks.com/topic/124699-unique-account-numbers/#findComment-644100 Share on other sites More sharing options...
Mchl Posted September 17, 2008 Share Posted September 17, 2008 I hate account 'numbers' that are generated basing on user's name. I'd rather see some pure numeric, random number. Quote Link to comment https://forums.phpfreaks.com/topic/124699-unique-account-numbers/#findComment-644143 Share on other sites More sharing options...
Guardian-Mage Posted September 17, 2008 Share Posted September 17, 2008 IF you do want to use a completely random number like the last poster suggested just use this function function create_random_str($length){ $src = 'abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ@_'; $len = strlen($src) - 1; $randstr = ""; for($i=0; $i<$length; $i++) { $x = rand(0,$len); $randstr .= $src{$x}; } return $randstr; } Quote Link to comment https://forums.phpfreaks.com/topic/124699-unique-account-numbers/#findComment-644161 Share on other sites More sharing options...
kenrbnsn Posted September 17, 2008 Share Posted September 17, 2008 You don't need a loop in that function, use the shuffle() function: <?php function create_random_str($length){ $src = array_merge(range('a','z'),range(0,9),array('@','_')); shuffle($src); return implode('',array_slice($src,$length)); } ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/124699-unique-account-numbers/#findComment-644172 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.