str_shuffle(): shuffle a string

Shuffle characters when unpredictability is not required

str_shuffle() returns a random permutation of the bytes in a string. It is useful for demonstrations and non-security shuffling, but it must not be used to create passwords, tokens or other values that need to be unpredictable.

$text = 'abcdef';
echo str_shuffle($text);

For secrets or tokens, use random_bytes(), random_int(), or the secure Random API instead.

$string="abcdefghijk";
echo str_shuffle($string);
The result changes between runs; your output will probably differ.
kdifgbjache

Combining characters for a non-security shuffling demo

This example demonstrates string shuffling only. Do not use str_shuffle() to generate passwords, reset tokens or security secrets.
This example combines different character groups for a non-security demonstration, then shuffles them. We used substr string function to get short string by taking out first 8 chars of the string only.
Here is the code

$string1="abcdefghijklmnopqrstuvwxyz";
$string2="1234567890";
$string3="!@#$%^&*()_+";
$string=$string1.$string2.$string3;
$string= str_shuffle($string);
echo substr($string,0,8); 
this produces an 8-character shuffled string for demonstration only; do not use it as a password or security token.

r@o82#tv
The three character groups demonstrate concatenation and shuffling. The result is not secure or uniformly sampled and must never be treated as a password or token. For account passwords, prefer established authentication patterns and secure randomness rather than str_shuffle().

Example: Shuffling UTF-8 Strings

str_shuffle() operates on bytes. The following alternative uses mb_str_split() (requires mbstring) and shuffle() for Unicode characters, for display-only uses.

$str = "こんにちは";
$arr = mb_str_split($str);
shuffle($arr);
echo implode('', $arr);  // Output: Shuffled Japanese characters (varies)

Example: Shuffling letters and numbers for a non-security demo

$shuffled = str_shuffle('abcdefghijklmnpqrstuvwxyz1234567890');
echo substr($shuffled, 0, 8);  // Output: Shuffled demo output (varies)

String Functions chr(): Character from byte value


Subscribe to our YouTube Channel here



plus2net.com







suchira

17-06-2015

hey.this site is best.good job friend and wish you all the best carryon..




PHP video Tutorials
✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer