function word_shuffle( $text ) {
$len = strlen($text);
if ( $len > 3 ) {
$sub = substr($text, 1, ($len - 2));
$sub = str_shuffle($sub);
$shuffle = $text{0} . $sub . $text{($len - 1)};
return $shuffle;
} else {
return $text;
}
}
$text = isset($_POST['text']) ? trim($_POST['text']) : '';
echo '<form action="index.php" method="post"><textarea name="text">' . htmlspecialchars($text) . '</textarea>' .
'<p><input type="submit" name="submit" value="shuffle" /></p></form>';
if ( !empty($_POST) ) {
$array = explode(' ', $text);
var_dump($array);
foreach ($array as $val)
echo word_shuffle($val) . ' ';
}