Created
March 10, 2014 07:15
-
-
Save shouhei/9460724 to your computer and use it in GitHub Desktop.
make random strings to use php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class RandStr{ | |
private $small = 'abcdefghjiklmnopqrstuvwxyz'; | |
private $large = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; | |
private $num = '0123456789'; | |
private $all_ary = array(); | |
function __construct(){ | |
array_push($this->all_ary,$this->small,$this->large,$this->num); | |
} | |
public function add_str($param = array()){ | |
foreach($param as $key => $value){ | |
$this->$key = $value; | |
$this->all_ary[] = $value; | |
} | |
} | |
public function mk_rd_str($length,$param = array('small','large','num')) { | |
$carset = ''; | |
foreach($param as $val){ | |
$charset .= $this->$val; | |
} | |
$charset_length = strlen($charset); | |
$string = ''; | |
for ($i = 0; $i < $length; $i++) { | |
$string .= $charset[mt_rand(0, $charset_length - 1)]; | |
} | |
return $string; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment