Str_shuffle
- (PHP 4 >= 4.3.0, PHP 5, PHP 7)
- Str_shuffle-randomly shuffles A string
- Str_shuffle-randomly disrupts a string
Description
str_shuffle($str)//str_shuffle() shuffles a string. One permutation of all possible is created.//str_shuffle() 函数打乱一个字符串,使用任何一种可能的排序方案。
Caution
- This function is does not generate cryptographically secure values, and should not being used for cryptographic purposes. If you need a cryptographically secure value, consider using Random_int (), random_bytes (), or openssl_random_pseudo_bytes ( ) instead.
- This function does not generate a secure encrypted value and should not be used for encryption purposes. Consider using openssl_random_pseudo_bytes () If you need a secure encrypted value.
Parametersstr
- The input string.
- The input string.
Return Values
- Returns the shuffled string.
- Returns the scrambled string.
Changelog
- 7.1.0 the internal randomization algorithm have been changed to use the? Mersenne Twister Random number Generator instead of the libc rand function.
- The built-in random algorithm was changed from the libc rand function? A pseudo-random number algorithm for rotational modeling of Mason.
Examples
<?php/*** Created by Phpstorm.* User:zhangrongxiang* DATE:2018/3/7* Time: PM 10:04 */$str="ABCDE";Echo Str_shuffle( $str ).Php_eol;Echo Str_shuffle( $str ).Php_eol;Echo Str_shuffle( $str ).Php_eol;Echo Str_shuffle( $str ).Php_eol;/////////////////////////////////////////////////////////////////////////////////functionScramble_word( $word ){if ( strlen( $word )<2 ){return $word;}Else{return $word{0} .Str_shuffle( substr( $word, 1,-1 ) ).$word{strlen( $word )-1};}}//echo preg_replace ('/(\w+)/E ', ' Scramble_word ("\1") ', ' A quick brown fox jumped over the the lazy Dog. ');EchoScramble_word( "A Quick brown fox jumped over the lazy dog." ).Php_eol;////////////////////////////////////////////////////////////////////////////////**this function is affected by srand ():*/Srand( 12345 );Echo Str_shuffle( ' Randomize me ' ).Php_eol; //DEMMIEZR aonEcho Str_shuffle( ' Randomize me ' ).Php_eol; //izadmeo rmenSrand( 12345 );Echo Str_shuffle( ' Randomize me ' ).Php_eol; //DEMMIEZR aon//////////////////////////////////////////////////////////////////////////////Not very trueSrand( Time());functionUnicode_shuffle( $string, $chars, $format=' UTF-8 ' ){$rands=[]; for ( $i=0; $i<$chars; $i++){$rands[ $i ]=Rand( 0, Mb_strlen( $string, $format ) );}$s=NULL; foreach ( $rands as $r ){$s.=Mb_substr( $string, $r, 1, $format );}return $s;}EchoUnicode_shuffle( "The object of all things", 3 ).Php_eol;
See
- http://php.net/manual/zh/function.str_shuffle.php
All rights reserved
The Str_shuffle () function of the PHP string is used