Tuesday, November 8, 2011

php code for perfect palindrome









<?php

    $word  = array("test","racecar","axe","madam","hu","ada");

    for($i=0;$i<=5;$i++)
    {
            if(strlen($word[$i])>2)
            {
                if(strlen($word[$i])%2==1)
                {
                        $word2[$i] = strrev($word[$i]);
                       
                        if($word[$i] == $word2[$i])
                        {
                            echo"<p>$word[$i] is a perfect palindrome</p>";
                        }
                   
                }

            }
            else
           
            if(strlen($word[$i])<3)
            {
                    echo"<p>$word[$i] is not a palindrome bacause it has less than 3 characters</p>";
            }
            if(strlen($word[$i])%2 !=1)
            {
                    echo"<p>$word[$i] is not a palindrome because it has even number of characters</p>";
            }
            if($word[$i] != $word2[$i])
            {
                    echo"<p>$word[$i] is not a palindrome because when we reverse the character, it produce different meaning</p>";
            }

    }
?>
Related Posts Plugin for WordPress, Blogger...