Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php generate random string of characters

function generateRandomString($length = 25) {
    $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $charactersLength = strlen($characters);
    $randomString = '';
    for ($i = 0; $i < $length; $i++) {
        $randomString .= $characters[rand(0, $charactersLength - 1)];
    }
    return $randomString;
}
//usage 
$myRandomString = generateRandomString(5);
Comment

generate random string php

$random = Str::random(20); // the other anwsers on codegrepper gave me headache
Comment

php generate random string

function RandomString($length = 6) {
    $original_string = array_merge(range(0,29), range('a','z'), range('A', 'Z'));
    $original_string = implode("", $original_string);
    return substr(str_shuffle($original_string), 0, $length);
}
echo RandomString(6);
Comment

php random string

function rand_str() {
    $characters = '0123456789-=+{}[]:;@#~.?/&gt;,&lt;|!"£$%^&amp;*()abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $randomstr = '';
    for ($i = 0; $i < random_int(50, 100); $i++) {
      $randomstr .= $characters[rand(0, strlen($characters) - 1)];
    }
    return $randomstr;
  }
Comment

generate random string php

function RandomString($length = 10) {
    return substr(str_shuffle(str_repeat($x='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', ceil($length/strlen($x)) )),1,$length);
}

echo  RandomString();  
Comment

Generate Random String in PHP

phpCopy<?php 
$Random_str = uniqid();  
echo "Random String:", $Random_str, "
";
?> 
Comment

random string generator php

function generateRandomString($length = 10) {
    $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $charactersLength = strlen($characters);
    $randomString = '';
    for ($i = 0; $i < $length; $i++) {
        $randomString .= $characters[rand(0, $charactersLength - 1)];
    }
    return $randomString;
}

Output the random string with the call below:

// Echo the random string.
// Optionally, you can give it a desired string length.
echo generateRandomString();
Comment

php random string

function generateRandomString($digits) {
    $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $randstring = '';
    for ($i = 0; $i < $digits; $i++) {
        $randstring .= $characters[rand(0, strlen($characters))];
    }
    return $randstring;
}
echo generateRandomString(24);
Comment

random string generator php

<?php
    function RandomString()
    {
        $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
        $randstring = '';
        for ($i = 0; $i < 10; $i++) {
            $randstring = $characters[rand(0, strlen($characters))];
        }
        return $randstring;
    }

    RandomString();
    echo $randstring;
Comment

random string in php

$len = 9;

$random = str_shuffle(sub_str('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890', 10, $len));
Comment

php random characters

function random_chars($length = 12)
{
    $chars      = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_?,.";
    $rand_chars = substr( str_shuffle( $chars ), 0, $length );
    return $rand_chars;
}
Comment

Generate Random String in PHP

phpCopy<?php 
echo uniqid('user_');
?> 
Comment

Generate Random String in PHP

phpCopy<?php
 
echo "Out1: ",substr(md5(time()), 0, 16),"
";
 
echo "Out2: ",substr(sha1(time()), 0, 16),"
";
 
echo "Out3: ",md5(time()),"
";
 
echo "Out4: ",sha1(time()),"
";
 
?>
Comment

generate random string php

function gen_uid($l=5){
   return substr(str_shuffle("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"), 10, $l);
}
echo gen_uid();
Comment

generate random string php

function gen_uid($l=5){
   return substr(str_shuffle("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"), 10, $l);
}
echo gen_uid();
Comment

generate random string in php

/**
 * Generate a random string, using a cryptographically secure 
 * pseudorandom number generator (random_int)
 *
 * This function uses type hints now (PHP 7+ only), but it was originally
 * written for PHP 5 as well.
 * 
 * For PHP 7, random_int is a PHP core function
 * For PHP 5.x, depends on https://github.com/paragonie/random_compat
 * 
 * @param int $length      How many characters do we want?
 * @param string $keyspace A string of all possible characters
 *                         to select from
 * @return string
 */
function random_str(
    int $length = 64,
    string $keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
): string {
    if ($length < 1) {
        throw new RangeException("Length must be a positive integer");
    }
    $pieces = [];
    $max = mb_strlen($keyspace, '8bit') - 1;
    for ($i = 0; $i < $length; ++$i) {
        $pieces []= $keyspace[random_int(0, $max)];
    }
    return implode('', $pieces);
}
Comment

Generate Random String in PHP

phpCopy<?php
 $x = 0;
 $y = 10;
$Strings = '0123456789abcdefghijklmnopqrstuvwxyz';
echo "Gen_rand_str: ",substr(str_shuffle($Strings), $x, $y), "
";

$a = 0;
$b = 20;
$Strings='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
echo "Gen_My_Pass: ",'hello.'.substr(str_shuffle($Strings), $a, $b).'.World',"
";
?>
Comment

Generate Random String in PHP

phpCopy<?php
 
echo "Output-1: ",bin2hex(random_bytes(10)),"
";
 
echo "Output-2: ",bin2hex(random_bytes(20)),"
";
 
echo "Output-3: ",bin2hex(random_bytes(24)),"
";
 
?>
Comment

php string random

$string = bin2hex(openssl_random_pseudo_bytes(10)); // 20 chars
Comment

random String Function PHP

function generateRandomString($length = 10) {
    $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $charactersLength = strlen($characters);
    $randomString = '';
    for ($i = 0; $i < $length; $i++) {
        $randomString .= $characters[rand(0, $charactersLength - 1)];
    }
    return $randomString;
}


// Echo the random string.
// Optionally, you can give it a desired string length.
echo generateRandomString();
Comment

PREVIOUS NEXT
Code Example
Php :: php xml to array 
Php :: laravel turn off timestamps 
Php :: “laravel migration data types” 
Php :: laravel has table 
Php :: php referral 
Php :: composer stripe 
Php :: php explode trim 
Php :: laravel/framework[v5.8.0, ..., 5.8.x-dev] require php ^7.1.3 - your php version (8.1.6) does not satisfy that req 
Php :: string contains string laravel 
Php :: pi() in php 
Php :: background image in laravel blade 
Php :: get wordpress page link by id 
Php :: wordpress change site address 
Php :: get user ip in php 
Php :: wordpress if admin 
Php :: laravel validate telephone number 
Php :: get key of last element php 
Php :: api headers php 
Php :: ip condition in php 
Php :: validate year laravel 
Php :: get user ip laravel 
Php :: home url wordpress 
Php :: php file_get_contents url 
Php :: last login date time in wordpress 
Php :: laravel get random row 
Php :: flutter boxdecoration add border 
Php :: woocommerce-cart-count 
Php :: php convert string to utf8 
Php :: php get uploaded file extension 
Php :: php reindex array after unset 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =