PHP Classes

PHP Randomly Generate String: Generate random string based on given parameters

Recommend this page to a friend!
  Info   View files Example   View files View files (2)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 101 All time: 9,777 This week: 673Up
Version License PHP version Categories
randomstring 1.0Shareware5PHP 5, Text processing
Description 

Author

This class can generate random string based on given parameters.

It can take several parameters and returns a string encoded using UTF-8 with random characters that match the required of the specified parameters. Currently it can take parameters that define:

- Minimum and maximum numbers of characters to use in the string
- List of characters to use in the string, as well the minimum quantity of characters to return from the list

In Spanish:

Esta clase te permitira generar una cadena aleatoria, dando algunos parametros como:

- min y max numero de caracteres a usar en la cadena
- lista de caracteres a usar en la cadena, especificando el numero minimo de caracteres por lista
- el resultado final es codificado en el formato utf-8, asi la cadena se mostrara correctamente.

Picture of Roberto Sanchez
  Performance   Level  
Name: Roberto Sanchez <contact>
Classes: 1 package by
Country: Cuba Cuba
Age: ???
All time rank: 440514 in Cuba Cuba
Week rank: 295 Up1 in Cuba Cuba Up

Example

<?php
include_once 'lib/randomstring.class.php';
$randstr = new randomstring();

//Puede crear su propia lista de caracteres en la propiedad ->string
$randstr->strings=array(
   
'upper' =>"ABCDEFGHIJKLMNOPQRSTUVWXYZ",
   
'lower' =>"abcdefghijklmnopqrstuvwxyz",
   
'nums' =>"0123456789",
   
'spec' =>"`~?!@#$%^&'\"_-+=/*\\.,:;()[]{}",
   
'utf8' =>"~???????",
);

//Y declarar la cantidad minima de caracteres de esa lista en la propiedad ->counter
$randstr->counter=array(
   
'upper' =>1,
   
'lower' =>1,
   
'nums' =>1,
   
'spec' =>1,
   
'utf8' =>1,
);
/*
*****NOTA*****
Tenga en cuenta que las propiedades anteriores son de tipo array
y ambas tienen las mismas claves. Esta clase solo creara la cadena con
las claves coincidentes de ambas propiedades. Si ambas propiedades no tienen
claves coincidentes entonces no se generara ninguna cadena y la function
generatepassword no devolvera ningun valor

Puede declarar la cantidad minima y maxima de caracteres que tendra la cadena.
Si declara la misma cantidad de minima y maxima entonces la cadena generada
tendra siempre la misma longitud. Si declara cantidades distintas entonces la
cadena tandra una longitus aleatoria entre los valores minimo y maximo establecidos
*/
$randstr->size['min'] = 30;
$randstr->size['max'] = 50;



echo
$randstr->generatePassword();


  Files folder image Files  
File Role Description
Files folder imagelib (1 file)
Accessible without login Plain text file exampleRandomstring.php Example example for randomstring

  Files folder image Files  /  lib  
File Role Description
  Plain text file randomstring.class.php Class Class source file

 Version Control Unique User Downloads Download Rankings  
 0%
Total:101
This week:0
All time:9,777
This week:673Up