-
Notifications
You must be signed in to change notification settings - Fork 0
random plugin
The Random Plugin for CodeIgniter is a simple that allow to generate random string of a specific lenght.
It's composed by two functions, the first help you to generate random strings, and the second to generate random int.
[b]Plugin home :[/b] [url=http://www.kromack.com/codeigniter/plugin-random-pour-codeigniter/]Random Plugin[/url]
[b]How to use :[/b]
[code] <?php
$this->load->plugin('random');
echo generate(32); echo generateInt(8);
?> [/code]
[b]Plugin's code :[/b]
[code] <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
-
Ramdom string plugin for CodeIgniter applications
-
@author : Samuel Sanchez, March 2009, http://www.kromack.com/
-
@license : free
-
@see http://www.kromack.com/codeigniter/plugin-random-pour-codeigniterplugin-random-pour-codeigniter/ */
/**
-
Return a ramdom string of $lenght size.
-
@param int $lenght
-
@return string */ function generate($lenght) { $ensemble = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '1', '2', '3', '4');
if($lenght > sizeof($ensemble)) {
while($lenght > sizeof($ensemble)) { foreach($ensemble as $row) { $ensemble[] = $row; } }
}
$ramdom = array_rand($ensemble, $lenght);
$string = '';
foreach($ramdom as $i) { $string = $string . $ensemble[$i]; }
return $string; }
/**
-
Return a ramdom int of $lenght size.
-
@param int $lenght
-
@return string */ function generateInt($lenght) { $ensemble = array('1', '2', '3', '4', '5', '6', '7', '8', '9');
if($lenght > sizeof($ensemble)) {
while($lenght > sizeof($ensemble)) { foreach($ensemble as $row) { $ensemble[] = $row; } }
}
$ramdom = array_rand($ensemble, $lenght);$string = '';
foreach($ramdom as $i) { $string = $string . $ensemble[$i]; }
return $string; }
-
?> [/code]