Return to Snippet

Revision: 42277
at March 2, 2011 18:14 by chopbust


Initial Code
function convert_to_username($original, $passno) {
	$xname = explode('A/L', $original);
	$xname2 = explode('A/P', $xname[0]);
	$xname3 = explode('BIN', $xname2[0]);
	$xname4 = explode('@', $xname3[0]);
	
	$uname = str_replace(' ', '', $xname4[0]);	
	$uname = str_replace(',', '', $uname);
	$uname = str_replace('.', '', $uname);
	$uname = str_replace('-', '', $uname);
	$uname = str_replace('`', '', $uname);
	$uname = str_replace('(', '', $uname);
	$uname = str_replace(')', '', $uname);	
	$uname = strtolower(str_replace('\'', '', $uname));	
	$uname = strtolower(str_replace('/', '', $uname));
	$uname = substr($uname,0,12);
	
	$passno_strip = substr($passno, 0, 2);
		
	//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)
	$check = $sql->selectSQL("COUNT(*) as how_many","admin_login","WHERE uname LIKE '$uname'");
	
	//if already exist, append passno into the username to avoid duplicate username
	if ($check > 0) {
		$uname = substr($uname,0,10);
		$uname .= $passno_strip;
	}
	
	$uname = strtolower($uname); //turn all lowercase
	
	return $uname;}

Initial URL

                                

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

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

Initial Title
Create a username using Full Name

Initial Tags

                                

Initial Language
PHP