randomize words of a string php code example
Example 1: PHP random string generator
function generateRandomString($length = 25) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
return $randomString;
}
$myRandomString = generateRandomString(5);
Example 2: random word using a wordlist php
$file = file('File Location');
$wCount = count($file);
echo $file[rand(0, $wCount - 1)];
echo file('File Location')[rand(0, count(file('File Location')) - 1)];