• Register

For all web developpers and webpage layout makers, also for beginners who desire to learn! :-)

Post tutorial Report RSS Object oriented name generator

An addendum and a rewrite of an old name generator.

Posted by on - Basic Server Side Coding

This is a rewrite of an old name generator as well as an addendum to the old name generator how-to guide here: Moddb.com

<?php

class NameGeneration
{
  //$vowel boolean - true for vowel, false for consonant
  function randLetter($vowel)
    {
    $letter = "";
    $vowels = array("a", "e", "o", "u");
    $consonants = array("b", "c", "d", "v", "g", "t", "l", "f");
  
    switch($vowel)
      {
        case true:
        $letter = $vowels[array_rand($vowels, 1)];
        break;
        
        case false:
        $letter = $consonants[array_rand($consonants, 1)];
        break;
      }
  
    return $letter;
  }
  
  function generateName()
  {
  $name = $this->randLetter(false) . "" . $this->randLetter(true) . "" . "" . $this->randLetter(false) . "" . $this->randLetter(true) . "" . $this->randLetter(true) . "";
  echo $name;
  }
}

$newname = new NameGeneration;
$newname -> generateName();

?>

this rewrite was done by request of a community member who wished an OOP (object oriented programming) version of the script. To note, it seems this name generator is better done in jQuery/JavaScript/PHP combo rather than PHP alone if you are going to make a serious website.

Post comment Comments
Salsa_Shark
Salsa_Shark - - 1,292 comments

neat!

Reply Good karma Bad karma+3 votes
Post a comment

Your comment will be anonymous unless you join the community. Or sign in with your social account: