search for in the  
<str_rot13str_split>
Last updated: Thu, 19 May 2005

str_shuffle

(PHP 4 >= 4.3.0, PHP 5)

str_shuffle -- Randomly shuffles a string

Description

string str_shuffle ( string str )

str_shuffle() shuffles a string. One permutation of all possible is created.

Example 1. str_shuffle() example

<?php
$str
= 'abcdef';
$shuffled = str_shuffle($str);

// This will echo something like: bfdaec
echo $shuffled;
?>

See also shuffle() and rand().



User Contributed Notes
str_shuffle
Michiel van den boogaard
17-Jan-2005 04:03
Shortend function for PHP < 4.3
<?php 
function RandomPass($numchar

  
$word = "a,b,c,d,e,f,g,h,i,j,k,l,m,1,2,3,4,5,6,7,8,9,0"
  
$array=explode(",",$word); 
  
shuffle($array); 
  
$newstring = implode($array,""); 
   return
substr($newstring, 0, $numchar); 

?>
aidan at php dot net
26-Aug-2004 05:31
This functionality is now implemented in the PEAR package PHP_Compat.

More information about using this function without upgrading your version of PHP can be found on the below link:

http://pear.php.net/package/PHP_Compat
sfalcon_(at)_pymesweb_(dot)_com
26-Aug-2004 10:28
You can use str_shuffle to make simple and nice random passwords:

function random_passwd($numchar) {
     $string =str_shuffle("abcefghijklmnopqrstuvwxyz1234567890");
     $password = substr($string,1,$numchar);

     return($password);
}

echo random_passwd('8') // Will return something like "xa3dh214" =)
floweb at yahoo dot com
16-Sep-2003 12:09
this is basically the equivelent to the str_shuffle they use

function str_shuffle($word){
   for($i=0;$i<strlen($word);$i++)
       $array[]=$word[$i];
  
   shuffle($array);
   for($i=0;$i<count($array);$i++)
       $newstring .= $array[$i];
      
   return $newstring;
}

sidenote: wrote this when me and a friend were writing some code and i realized i was using 4.3.0 and he was using 4.2.0 needless to say my code took less lines :)

<str_rot13str_split>
 Last updated: Thu, 19 May 2005
Copyright © 2001-2005 The PHP Group
All rights reserved.
This unofficial mirror is operated at: The Server Pages
Last updated: Thu May 19 17:35:34 2005 CDT