Example 2

We would like to create an anagram for a word. (Jumble the letters.)

if(!isset($word)) $word="wizard"; //make sure word is not null
for($i=0;$i<strlen($word);$i++) { 
  $letters[$i]=substr($word,$i,1);
} //each letter of word
shuffle($letters);  //an array function
$anagram=implode($letters);
echo "One anagram of $word is $anagram.";

The output will be a random anagram of the word. You can put a word in the URL of this page and refresh the page to see an anagram for your word.

One anagram of wizard is rwzadi.

Example 3: A cryptogram

$alphabet="";
for($i=65;$i<65+26;$i++) {
	$alphabet.=chr($i);  //uses the ascii value to return the character
	$letters[$i-65]=chr($i); //put the character in the array
} // A to Z
echo "The alphabet is $alphabet<BR>";
shuffle($letters);
$code=implode($letters);
echo "The code is $code.<BR>";
$sentence="I think therefore I am.";
$sentence=strtoupper($sentence);
$crypt=strtr($sentence , $alphabet , $code); //encrypt
echo 'Here is the cryptogram:<BR>';
echo $crypt.'<BR>';
The output will look something like this: The alphabet is ABCDEFGHIJKLMNOPQRSTUVWXYZ
The code is WVLEPIHUKXSYBCQFDTZNRJAMOG.
Here is the cryptogram:
K NUKCS NUPTPIQTP K WB.