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

Report article RSS Feed Object oriented name generator

An addendum and a rewrite of an old name generator.

Posted by feillyne on May 14th, 2013
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 code:
<?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 May 14 2013, 9:49am says:

neat!

+3 votes     reply to comment
Post a Comment
click to sign in

You are not logged in, your comment will be anonymous unless you join the community today (totally free - or sign in with your social account on the right) which we encourage all contributors to do.

2000 characters limit; HTML formatting and smileys are not supported - text only

Established
Dec 6, 2009
Privacy
Public
Subscription
Open to all members
Contact
Send Message
Email
Members Only
Membership
Join this group
Group Watch
Track this group
Tutorial
Browse
Tutorials
Report Abuse
Report article
Related Groups
Inside the Page
Inside the Page Hobbies & Interests group with 54 members
Web devs & web game devs
Web devs & web game devs Hobbies & Interests group with 35 members