Advertisement
aris-kun

Ninja Name

Apr 18th, 2016
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.80 KB | None | 0 0
  1. <?php
  2. class Ninja
  3. {
  4.     private $fname, $oname, $lname;
  5.  
  6.     public function __construct()
  7.     {
  8.         $this->alphabet = range('a', 'z');
  9.         $this->fname = array('agile', 'blackened', 'crouching', 'deadly', 'ethereal', 'fierce', 'glorious', 'hidden', 'imperial', 'jumping', 'kick', 'legendary', 'mighty', 'night', 'obsidian', 'prowling', 'quick', 'roaring', 'shadow', 'thoughtful', 'undying', 'vivacious', 'whispering', 'lurking', 'yearning', 'zealous');
  10.         $this->oname = array('lotus', 'sapphire', 'steel', 'pearl', 'silk', 'night', 'diamond', 'jade', 'amethyst', 'typhoon', 'assasin', 'star', 'chrome', 'emerald', 'moon', 'dragonheart', 'sword', 'silver', 'hurricane', 'wind', 'rebel', 'gold', 'crystal', 'stealth', 'bronze', 'sunset', 'fire', 'dark', 'warrior', 'mountain', 'shinobi');
  11.         $this->lname = array('anaconda', 'baboon', 'cheetah', 'dragon', 'elephant', 'fox', 'grasshopper', 'hawk', 'iguana', 'jaguar', 'kangaroo', 'leopard', 'monkey', 'numbat', 'ostrich', 'panda', 'quail', 'rabbit', 'serpent', 'tiger', 'unicorn', 'viper', 'warthog', 'spider', 'yak', 'zebra');
  12.     }
  13.  
  14.     public function GetName($data, $fname = true)
  15.     {
  16.         $name = explode(' ', $data);
  17.  
  18.         if ($fname) :
  19.             $init = substr($name[0], 0, 1);
  20.         else :
  21.             $init = substr($name[1], 0, 1);
  22.         endif;
  23.        
  24.         $keyname = array_search($init, $this->alphabet);
  25.  
  26.         return $fname ? $this->fname[$keyname] : $this->lname[$keyname];
  27.     }
  28.  
  29.     public function GetOName($data)
  30.     {
  31.         $date = explode(' ', $data);
  32.         $key = $date[0] - 1;
  33.  
  34.         return $this->oname[$key];
  35.     }
  36.  
  37.     public function GetNinjaName($fullname, $date)
  38.     {
  39.         $name = $this->GetName($fullname) . ' ' . $this->GetOName($date) . ' ' . $this->GetName($fullname, false);
  40.  
  41.         return $name;
  42.     }
  43. }
  44. ?>
  45. <!DOCTYPE html>
  46. <html>
  47.     <head>
  48.         <title>Your Ninja Name</title>
  49.         <style type="text/css">
  50.             #FloatBox {
  51.                 width: 400px;
  52.                 height: 150px;
  53.                 position: absolute;
  54.                 top: 50%;
  55.                 left: 50%;
  56.                 margin-top: -75px;
  57.                 margin-left: -200px;
  58.                 border: 2px solid #BBB;
  59.             }
  60.  
  61.             table {
  62.                 width: 100%;
  63.             }
  64.  
  65.             table td:first-child {
  66.                 text-align: right;
  67.             }
  68.         </style>
  69.     </head>
  70.     <body>
  71.         <section id="FloatBox">
  72.             <div style="margin: 10px;">
  73.                 <form action="" method="POST">
  74.                     <table>
  75.                         <tr>
  76.                             <td>Nama Lengkap</td>
  77.                             <td><input type="text" name="fullname" size="25" value="rudi hermanto" /></td>
  78.                         </tr>
  79.                         <tr>
  80.                             <td>Tanggal Lahir</td>
  81.                             <td><input type="text" name="borndate" size="20" value="22 juni 2000" /></td>
  82.                         </tr>
  83.                         <tr>
  84.                             <td></td>
  85.                             <td><input type="submit" value="GENERATE" /></td>
  86.                         </tr>
  87.                     </table>
  88.                 </form>
  89.                 <?php
  90.                 if ($_POST) :
  91.                     $ninja = new Ninja();
  92.                     echo $ninja->GetNinjaName($_POST['fullname'], $_POST['borndate']);
  93.                 endif;
  94.                 ?>
  95.             </div>
  96.         </section>
  97.     </body>
  98. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement