|
Yazan
|
Konu: Rasgele kelime üreten class (Okunma Sayısı 1021 defa)
|
phparmy
phparmy
PHP Stajyeri

Offline
Mesaj Sayısı: 372
Elektronik imzam.
|
rand_word.class.php <?php
/*************************************************************************** * * Author : Eric Sizemore ( www.secondversion.com & www.phpsociety.com ) * Package : Random Word * Version : 1.0.0 * Copyright: (C) 2006 Eric Sizemore * Site : www.secondversion.com & www.phpsociety.com * Email : esizemore05@gmail.com * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * ***************************************************************************/
// Slightly inspired by class randomWord by kumar mcmillan class rand_word { var $vowels = array('a','e','i','o','u','y'); var $consonants = array('b','c','d','f','g','h','j','k','l','m','n','p','r','s','t','v','w','z','ch','qu','th','xy'); var $word = '';
function rand_word($length = 5, $lower_case = true, $ucfirst = false, $upper_case = false) { $done = false; $const_or_vowel = 1; while (!$done) { switch ($const_or_vowel) { case 1: $this->word .= $this->consonants[array_rand($this->consonants)]; $const_or_vowel = 2; break; case 2: $this->word .= $this->vowels[array_rand($this->vowels)]; $const_or_vowel = 1; break; } if (strlen($this->word) >= $length) { $done = true; } }
$this->word = substr($this->word, 0, $length); $this->word = ($lower_case) ? strtolower($this->word) : $this->word; $this->word = ($ucfirst) ? ucfirst(strtolower($this->word)) : $this->word; $this->word = ($upper_case) ? strtoupper($this->word) : $this->word; return $this->word; } }
?>
example.php <?php
/*************************************************************************** * * Author : Eric Sizemore ( www.secondversion.com & www.phpsociety.com ) * Package : Random Word * Version : 1.0.0 * Copyright: (C) 2006 Eric Sizemore * Site : www.secondversion.com & www.phpsociety.com * Email : esizemore05@gmail.com * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * ***************************************************************************/
require_once('rand_word.class.php'); // rand_word() accepts the following parameters // length, use lowercase (true/false), ucfirst (true/false), use uppercase (true/false) // the below would output something similar to: Maquu $word = new rand_word(5, false, true); echo $word->word;
?>
|
|
|
|
|
Logged
|
|
|
|
nobody
Yeni Kullanıcılar
Offline
Mesaj Sayısı: 6
|
alphanumeric karekterler üretmiyordu ufak bir eklentiyle artık sayısal veriler ile karışık üretiyor. <?php class rand_word { var $vowels = array('a','e','i','o','u','y'); var $consonants = array('b','c','d','f','g','h','j','k','l','m','n','p','r','s','t','v','w','z','ch','qu','th','xy','0','1','2','3','4','5','6','7','8','9'); var $word = '';
function rand_word($length = 5, $lower_case = true, $ucfirst = false, $upper_case = false) { $done = false; $const_or_vowel = 1; while (!$done) { switch ($const_or_vowel) { case 1: $this->word .= $this->consonants[array_rand($this->consonants)]; $const_or_vowel = 2; break; case 2: $this->word .= $this->vowels[array_rand($this->vowels)]; $const_or_vowel = 1; break; } if (strlen($this->word) >= $length) { $done = true; } }
$this->word = substr($this->word, 0, $length); $this->word = ($lower_case) ? strtolower($this->word) : $this->word; $this->word = ($ucfirst) ? ucfirst(strtolower($this->word)) : $this->word; $this->word = ($upper_case) ? strtoupper($this->word) : $this->word; return $this->word; } }
?>
|
|
|
|
|
Logged
|
|
|
|
|
 |