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

Post tutorial Report content RSS feed 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.

Comments
Salsa_Shark
Salsa_Shark

neat!

Reply Good karma Bad karma+3 votes
Post a comment
Sign in or join with:

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.

Established
Privacy
Public
Subscription
Open to all members
Contact
Send Message
Membership
Join group
Group watch
Start tracking
Tutorial
Browse
Tutorials
Share
Related Groups
Inside the Page
Inside the Page Hobbies & Interests with 56 members
Web devs & web game devs
Web devs & web game devs Hobbies & Interests with 42 members