shuffle string
<?php function shuffle($str) { $shuffled = ""; $l = strlen($str); for ($i = 0; $i < $l; $i++) { $ch = substr($str, $i, 1); if ($ch == ' ') continue; $shuffled .= $ch; } $shuffled = str_shuffle($shuffled); $i = 0; $shuffled_str = ''; for ($j = 0; $j < $l; $j++) { $ch = substr($str, $j, 1); if ($ch == ' ') $shuffled_str .= ' '; else $shuffled_str .= $shuffled[$i++]; } return $shuffled_str; } echo shuffle("This is a test"); ?>