skip to main
|
skip to sidebar
Most3
Easy to get, easy to lose
Saturday, May 26, 2007
PHP Random String Function
/**
* @version $Id: iString.php 25 2007-05-24 16:12:11Z $
*
*/
class iString {
protected $_digits = '0123456789';
protected $_lowercaseAlphas = 'abcdefghijklmnopqrstuvwxyz';
protected $_uppercaseAlphas = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
protected $_characters;
public function getRandom($minLength = 4, $maxLength = 4, $hasDigit = true,
$hasLowercaseAlpha = false, $hasUppercaseAlpha = false) {
$stringLength = rand($minLength, $maxLength);
if ($hasDigit) $this->_characters = $this->_digits;
if ($hasLowercaseAlpha) $this->_characters .= $this->_lowercaseAlphas;
if ($hasUppercaseAlpha) $this->_characters .= $this->_uppercaseAlphas;
$charactersLength = strlen($this->_characters);
$string = '';
for($i=0;$i<$stringLength;$i++) {
$pos = rand(0, $charactersLength-1);
$string .= substr($this->_characters, $pos, 1);
}
return $string;
}
/**
* encrypt a string
*
* @param string $string
* @return string
*/
public function encrypt( $string ) {
return md5(md5($string));
}
}
?>
No comments:
Post a Comment
Newer Post
Home
Subscribe to:
Post Comments (Atom)
Enter your search terms
Submit search form
Labels
cod highlight blogger
(1)
code syntax highlighter blogger
(1)
decode captcha
(1)
delicious
(1)
Fullshape
(1)
Halfshape
(1)
php imagecolorat
(1)
php rand
(1)
random string
(1)
Zend Filter
(1)
Zend Framework
(1)
全角
(1)
半角
(1)
转换
(1)
Archive
May
(4)
Domain Tools
No comments:
Post a Comment