Thursday, July 23, 2015

How to create customized unique id like YouTube video id


Dear friend,
Some time we need to generate unique id for your clietns. we can use mysql generator id if we need to use that Id in printing.

for example.
you are creating bill for your client. you need to mention client id. if you will enter client id -:1, it wont look good.

so i write some code to achieve this goal.

Code 1-: 

function idGenerator1($length) {
  $random = '';
  for ($i = 0; $i < $length; $i++) {
    $random .= chr(rand(ord('a'), ord('z')));
  }
  $random .= rand(0, 1) ? rand(0, 9) : chr(rand(ord('a'), ord('z')));
  return  strtoupper($random);
}