Posted in php functions
8948
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
246
This Month
1129
This Year
2392

No Items Found.

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

This is my test area for webdev. I keep a collection of code here, mostly for my reference. Also if i find a good link, i usually add it here and then forget about it. more...

Subscribe to weekly updates about things i have added to the site or thought interesting during the last week.

You could also follow me on twitter or not... does anyone even use twitter anymore?

If you found something useful or like my work, you can buy me a coffee here. Mmm Coffee. ☕

❤️👩‍💻🎮

🪦 2000 - 16 Oct 2022 - Boots
Random Quote

"Olivia, my eldest daughter, caught measles when she was seven years old. As the illness took its usual course I can remember reading to her often in bed and not feeling particularly alarmed about it. Then one morning, when she was well on the road to recovery, I was sitting on her bed showing her how to fashion little animals out of coloured pipe-cleaners, and when it came to her turn to make one herself, I noticed that her fingers and her mind were not working together and she couldn’t do anything. 'Are you feeling all right?' I asked her. 'I feel all sleepy,' she said. In an hour, she was unconscious. In twelve hours she was dead. The measles had turned into a terrible thing called measles encephalitis and there was nothing the doctors could do to save her. That was...in 1962, but even now, if a child with measles happens to develop the same deadly reaction from measles as Olivia did, there would still be nothing the doctors could do to help her. On the other hand, there is today something that parents can do to make sure that this sort of tragedy does not happen to a child of theirs. They can insist that their child is immunised against measles. ...I dedicated two of my books to Olivia, the first was ‘James and the Giant Peach’. That was when she was still alive. The second was ‘The BFG’, dedicated to her memory after she had died from measles. You will see her name at the beginning of each of these books. And I know how happy she would be if only she could know that her death had helped to save a good deal of illness and death among other children."

I just checked google books for BFG, and the dedication is there. 

https://www.google.com.au/books/edition/_/quybcXrFhCIC?hl=en&gbpv=1 


Roald Dahl, 1986
Random CSS Property

box-decoration-break

The box-decoration-break CSS property specifies how an element's fragments should be rendered when broken across multiple lines, columns, or pages.
box-decoration-break css reference