Posted in php functions
6
5:04 am, October 23, 2021

generate random username function in php

a function that takes several random words and creates a user name from them. This will generate a user name with between one to three words and a prefix if prefix_show is set to true.

usage

generate_username($prefix_show = true);

assign to variable

$user_name = generate_username($prefix_show = true);

echo the user name

echo generate_username($prefix_show = true);

PHP

function generate_username($prefix_show = true) {
  		$usernames = "gang synonymous bumper return mar flint dove slimping wimp collop rich sardent irritating ponder bumble bee fly mongoose bitter syllable zonked functional sled monk educate raging tyres crow cruel godly fizzle reprimand hand ball cheery arrest flower gristly mitt chicken tidingskates aptbare pedlarplastic chew slurp cumbersome researcher fumbling booze slice warming unpopular tuna vocal dream flap jack mold warp hideous prepare immediate trip wire duster burning lay cotton thin antelope igloo crow supset morning bind chopping stutter hilarious victorious found moan ox surferread adoring gas bag unknown smell skating walking jumper live pole puppy resolute hide offer pale care shady beaver avocet twist woozy flush aged labourer washing worship puck ragged tart torn diced peg gang synonymous bumper return mar flint dove slimping wimp collop rich sardent irritating ponder bumble bee fly mongoose bitter syllable zonked functional sled monk educate raging tyres crow cruel godly fizzle reprimand hand ball cheery arrest flower gristly mitt chicken tidingskates aptbare pedlarplastic chew slurp cumbersome researcher fumbling booze slice warming unpopular tuna vocal dream flap jack mold warp hideous prepare immediate trip wire duster lay cotton thin antelope igloo crow supset morning bind chopping stutter hilarious victorious found moan ox surferread adoring gas bag unknown smell skating walking jumper live pole puppy resolute hide offer pale care shady beaver avocet twist woozy flush sucked aged labourer washing worship puck ragged tart torn diced peg enchanting satisfying honky reflecting shears slimeball ladder cauldron emerald potatoes tnt stick clay cyandye furnace lever sugar flint bookshelf signpost rails dirt jukebox torch map charcoal lava fire ice leather apple clock wheat saddle coalore sign carrots lilypad anvil air birchwood catdisc egg melon bedrock fern sponge sandstone sulphur bonemeal vines string sand gravel lilypad emerald cauldron air sandstone coalore bonemeal dandelion catdisc portal sand shears sponge vines clock wheat map gravel tripwire dispenser fern saddle furnace bow anvil trapdoor torch fire dirt ladder redstone blazerod carrots melon obsidian jukebox bedrock sulphur cyandye slimeball sugarcane snowball potatoes stick rails flowerpot flint charcoal egg lava catdisc stick bedrock rails map fire birchwood trapdoor leather charcoal potatoes melon coalore bookshelf obsidian furnace saddle ice cyandye cauldron dirt flint string emerald portal mycelium potato anvil flowerpot sign torch bow minecart jukebox fern sandstone redstone sponge lever shears dispenser dandelion sulphur ladder sugarcane carrots blazerod slimeball sugar tnt rake glaring business bloat bouquet goring smack gulp team cluster grist tittering commotion panel labour rope staff banner sdraught lead army worship husk gam bike parliament linkage moulting fold trembling brood orchestra breakdown bind parade promise shoal troupe kettle subtlety pod wilderness leap culture remuda sault harem building drove cache trip whiteness rag fluther coffle choir kindle balance shrewdness bavin nest wealth cache grist slate annoyance belt fraid sute audience safe rope puddling den anthology tabernacle labour cartload pray erst exaltation descent cletch sedge skulk harras farrow chirm dule compromise library husk cadge cohort coven shoal committee team eyrar lollies gatorade apricots sausage oil pie apples venison orange lard relish chowder garlic basmati pepperoni jerky granola doughnut vegetables syrup caviar tacos polenta pudding quiche sardines cordial icecream eggs milkshakes rice pepper pretzels oatmeal truffle mayonnaise paella clam salami chile salt tomatoe crackers pistachio burritos muesli coconut abalone raisins bagels opossum dingo ocelot ibis caribou sheep mussel rhino snail flyingfish raven elephant oyster ox hound walrus horse dunnock spoonbill stork peregrine crane auk eland buck gelding meerkat lizard kangaroo smelt orangutan lark hyena cattle cockroach mackerel cobra ponie rattlesnake quail penguin ptarmigan shrimp moth goose prairiedog cormorant lice cranky possessive gratified gleeful peaceful mild burning";
  		$usernames = explode(" ", $usernames);

  		$prefixes = "boss mad vip pwn dr slayer cool bad good scared frozen cold hot old new fresh dark fast spicy scary santa epic"; // mr mrs miss
  		$prefixes = explode(" ", $prefixes);
  		$prefix = $prefixes[array_rand($prefixes)];

  	  $loop = rand(0,2);
  	  $max = count($usernames);
  	  $max = $max - 1;
  	  $i = 0;
  	  $ruser = "";
  	  while ($i <= $loop) {
  	    shuffle($usernames);
  	    $una = rand(0,$max);
  	    if ( ($i == 0) && ($prefix_show === true) ) {
  	      $ruser .= "[".ucfirst($prefix)."] ";
  	    }
  	  	$ruser .= ucfirst($usernames[$una]) . " ";
  	    $i++;
  	  }
  	  return trim($ruser);

  	    /*
  	    shuffle($usernames);
  	    $ruser = ucfirst($usernames[$una[0]]) . " ";
  	    return $ruser .= ucfirst($usernames[$una[1]]);
  	    */
  	}

echo "<h3>user name with prefix</h3>";   
echo generate_username($prefix_show = true);
echo "<br>";
echo "<h3>user name with no prefix</h3>";
echo generate_username($prefix_show = false);

View Statistics
This Week
34
This Month
412
This Year
0

No Items Found.

Add Comment
Type in a Nick Name here
 
Search Code
Search Code by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code snippits here, mostly for my reference. Also if i find a good site, i usually add it here.

Join me on Substack if you want me to send you a collection of the things i have done or found or read for the week. Or follow me on twitter if you prefer, i dont post much but i probably should!

❤👩‍💻🕹

Random Quote

“Make no mistake: This is not your diary. You are not letting it all hang out. You are picking and choosing every single word.”


Dani Shapiro