Ads

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>";
            }

    }
?>

4 comments:

  1. how to convert this coding palindrome to C++??
    plze tell me...

    ReplyDelete
  2. Master C++ basic skill n u will know how to do it

    ReplyDelete
  3. Very Useful.. Thanks for sharing

    ReplyDelete
  4. what about noon and deed?

    ReplyDelete

Related Posts Plugin for WordPress, Blogger...