Thursday, 1 May 2014

PHP Program To Find A Anagram

An anagram is a rearrangement of the letters of one word or phrase to form another word or phrase.
In other words :"Any word or phrase that exactly reproduces the letters in another order is an anagram."
For example, "orchestra" is a transposition of "carthorse",
                      "dog" is a transposition of "god",
                      "army" is a transposition of "mary".
Note : The original word or phrase is known as the subject of the anagram.

A simple PHP Program for Anagram is given below

<?php
if(empty($word)) $word="dog";
for($i=0;$i<strlen($word);$i++) {
  $letters[$i]=substr($word,$i,1);
}
shuffle($letters);
$anagram=implode($letters);
echo "One anagram of $word is $anagram.";
?>

Output :

One anagram of dog is god
One anagram of dog is gdo,
One anagram of dog is dgo
and more....

When you execute the program then subjected word will change after refresh the page and that word or pharse will be anagram of subjected word or phrase.

No comments:

Post a Comment

Printing first 50 Fibonacci numbers Using PHP Program

Fibonacci series is a series of numbers in which each number is the sum of the two preceding numbers. For example. 0 , 1 , 1 , 2 , 3 , 5...