Autor Zpráva
MilanJ
Profil
Existuje v PHP funkce na generování náhodného řetězce o určitém počtu znaků?
Marty
Profil
Funkce přímo ne, ale není problém si jí udělat.

Inspirace: http://php.ftp.cvut.cz/manual/cs/function.rand.php#56246
mrako
Profil *
settype($template, "string");

$template = "1234567890abcdefghijklmnopqrstuvwxyz"; // z coho sa bude retazec skladat

function GetRandomString($length) {

global $template;

settype($length, "integer");
settype($rndstring, "string");
settype($a, "integer");
settype($b, "integer");

for ($a = 0; $a <= $length; $a++) {
$b = rand(0, strlen($template) - 1);
$rndstring .= $template[$b];
}

return $rndstring;

}
$kod = GetRandomString(30); // cislo urcuje pocet znakov v retazci
Toto téma je uzamčeno. Odpověď nelze zaslat.

0