Merhaba, Ziyaretçi. Lütfen giriş yapın veya üye olun.
Aktivasyon mailiniz gelmediyse buraya tıklayın.
04, 2008, 10:20:31 pm
42710 Mesaj 9329 Konu Gönderen: 17902 Üye
Son üye: Remark
Turk-Php.Com Forum  |  Yardım Forumları  |  PHP Yardım Forumu  |  PHP Class Deposu  |  Rasgele kelime üreten class « önceki sonraki »
Sayfa: [1] Yazdır
Yazan Konu: Rasgele kelime üreten class  (Okunma Sayısı 979 defa)
phparmy
phparmy
PHP Stajyeri
**
Offline Offline

Mesaj Sayısı: 371


Elektronik imzam.


Üyelik Bilgileri
Rasgele kelime üreten class
« : 02, 2006, 06:32:53 am »

rand_word.class.php
Kod:
<?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->word0$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
Kod:
<?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(5falsetrue);
echo 
$word->word;

?>

Logged
nobody
Yeni Kullanıcılar
*
Offline Offline

Mesaj Sayısı: 6


Üyelik Bilgileri
Ynt: Rasgele kelime üreten class
« Yanıtla #1 : 22, 2007, 12:56:44 pm »

alphanumeric karekterler üretmiyordu ufak bir eklentiyle artık sayısal veriler ile karışık üretiyor.
Kod:
<?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->word0$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
Sayfa: [1] Yazdır 
« önceki sonraki »
Gitmek istediğiniz yer:  


Turk-Php.Com Forum | SMF Forum Software © 2005, Simple Machines LLC. All Rights Reserved.