Sunday, 8 July 2012

Palindrome In PHP : kanhaiya lal (08/07/2012)

Source Code :=>
<?php

  $x="madam";                 //Input String
  checkPalindrom($x);  //function Calling
  function checkPalindrom($x) //function Definition
 {
       $len=strlen($x);  //get String Length
       $p=substr($x,0,1);    //get First Char
       $q=substr($x,$len-1,$len);  //get Last char
          if($p===$q)
      {
           if($x!=' ' && strlen($x)!=0)
          {
              $x=substr($x,1,$len-2); //get String with Remove first & last char of New String. 
             checkPalindrom($x);
          }
          else
              echo "True,It's Palindrome.";
      }
      else
     {
            die("No,It's not Palindrome.");  
     }
 }
?>


Output :=>


    True,It's Palindrome.

No comments:

Post a Comment