Generate random username based on full name php -


i want grab first name in lowercase concatenate first 2 characters after space , concatenate random number 0 100. if name "mike test" want output be: mikete3

function random_username($string) {     $pattern = " ";     $firstpart = strstr(strtolower($string), $pattern, true);     $secondpart = substr(strstr(strtolower($string), $pattern, false), 0, 3);     $nrrand = rand(0, 100);      $username = $firstpart.$secondpart.$nrrand;     return $username; }  echo random_username("mike test"); 

my function outputs "mike te84" , don't know how remove space.

try this, use trim remove space.

function random_username($string) { $pattern = " "; $firstpart = strstr(strtolower($string), $pattern, true); $secondpart = substr(strstr(strtolower($string), $pattern, false), 0,3); $nrrand = rand(0, 100);  $username = trim($firstpart).trim($secondpart).trim($nrrand); return $username; }  echo random_username("mike test"); 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -