₦airaland Forum

Welcome, Guest: Register • Login • With Google • Trending • Recent • New

Stats: 3,344,164 members, 8,510,476 topics. Date: Friday, 30 October 2026 at 01:02 PM

Toggle theme

Php Function To Generate A Random Expression - Programming - Nairaland

Nairaland Forum › Science/Technology › Programming › Php Function To Generate A Random Expression (1265 Views)

1 Reply

Php Function To Generate A Random Expression by chiwex(op): 10:11pm On Feb 02, 2018
If you are looking for a code function to generate a random expression, like password with alphanumeric or any other generate a random expression, use this function:

<?php
function GeraHash($qtd){
//Under the string $Caracteres you write all the characters you want to be used to randomly generate the code.
$Caracteres = 'ABCDEFGHIJKLMOPQRSTUVXWYZ0123456789';
$QuantidadeCaracteres = strlen($Caracteres);
$QuantidadeCaracteres--;

$Hash=NULL;
for($x=1;$x<=$qtd;$x++){
$Posicao = rand(0,$QuantidadeCaracteres);
$Hash .= substr($Caracteres,$Posicao,1);
}

return $Hash;
}

//Here you specify how many characters the returning string must have
echo GeraHash(30);
?>


source: http://php.net
1 Reply

Easy Way To Create A Random Password Generator In Python • Javascript Function To Java • User Defined Function To Validate Regular Expression In Javascript • 2 • 3 • 4

Is It Compulsory To Write An Algorithm Before Coding • Website Design • Is It Possible To Study 2 IT Courses At The Same Time?