The Str_shuffle () function of the PHP string is used

Source: Internet
Author: User
Tags cryptographically secure

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.