Create a username using Full Name


/ Published in: PHP
Save to your folder(s)

Takes a full string of a username - "Jack Bourne" and returns "jackbourne"

Parameters are $original (full name) and $passno (identification number etc)


Copy this code and paste it in your HTML
  1. function convert_to_username($original, $passno) {
  2. $xname = explode('A/L', $original);
  3. $xname2 = explode('A/P', $xname[0]);
  4. $xname3 = explode('BIN', $xname2[0]);
  5. $xname4 = explode('@', $xname3[0]);
  6.  
  7. $uname = str_replace(' ', '', $xname4[0]);
  8. $uname = str_replace(',', '', $uname);
  9. $uname = str_replace('.', '', $uname);
  10. $uname = str_replace('-', '', $uname);
  11. $uname = str_replace('`', '', $uname);
  12. $uname = str_replace('(', '', $uname);
  13. $uname = str_replace(')', '', $uname);
  14. $uname = strtolower(str_replace('\'', '', $uname));
  15. $uname = strtolower(str_replace('/', '', $uname));
  16. $uname = substr($uname,0,12);
  17.  
  18. $passno_strip = substr($passno, 0, 2);
  19.  
  20. //check if this username already exist (this is using my library, you have to change this with whatever mysql query u need. this is to check whether the name exists)
  21. $check = $sql->selectSQL("COUNT(*) as how_many","admin_login","WHERE uname LIKE '$uname'");
  22.  
  23. //if already exist, append passno into the username to avoid duplicate username
  24. if ($check > 0) {
  25. $uname = substr($uname,0,10);
  26. $uname .= $passno_strip;
  27. }
  28.  
  29. $uname = strtolower($uname); //turn all lowercase
  30.  
  31. return $uname;}

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.