Subscribe To Our Newsletter

Sign Up Now To Get Free Coupon Codes, Event Coupon Codes Updates, Offers Updates. It's 100% Free!

We Hate Spam! Really, It's terrible and we never do it.

Write an application that reads in a five-digit integer and determines whether it’s a palindrome. If the number is not five digits long, display an error message and allow the user to enter a new value.

I used many functions in this script. like Mod, Divide, Array Value Assigning, Float Function, then I used simple If .. else.. If conditional statement, and if within in statement.  
(Palindromes) A palindrome is a sequence of characters that reads the same backward as
forward.
For example, each of the following five-digit integers is a palindrome: 12321, 55555, 45554 and
11611.

Try this code. I hope you will learn from it.


 <?PHP  
      $inputs = array();  
      if (isset($_POST['submit'])) { //to check if the form was submitted  
           $value = isset($_POST['input0'])? $_POST['input0'] : null;  
           for($count = 1; $value != null; $count++){  
                array_push($inputs, $value);  
                $value = isset($_POST['input'.$count])? $_POST['input'.$count] : null;  
           }  
      }  
      var_dump($inputs);  
 ?>       
 <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">  
   <!-- to take multiple inputs copy the below line and change name="input" attribute -->  
   Enter input 1:&nbsp;<input type="text" name="input0" value="" /><br />  
   <input type="submit" name="submit" value="Submit" />  
 </form>  
 <?php  
 $dig = $inputs[0];  
 /*Now I need to get Mod 5th times from remaining value*/  
   $dig5 = ($dig % 10); //as mod of 10201 is 1 : $dig5 is Digit 5  
     $inputs[5] = $dig5; //1 is saved in 5th index  
   $dig4 = ($dig / 10); //value like 1020.1 : $dig4 is Digit 4  
     $dig4v = floor($dig4); //It will make 1020 : $dig4v is Digit 4th Value  
       $dig4vi = ($dig4v % 10); // as Mode of 1020 is 0 : $dig4vi is Digit 4th value index  
         $inputs[4] = $dig4vi; //0 is saved in 4th index  
   $dig3 = ($dig4v / 10); //value like 102.0 : $dig3 is Digit 3  
     $dig3v = floor($dig3); //It will make 102 : $dig3v is Digit 3rd Value  
       $dig3vi =($dig3v % 10); // as Mode of 102 is 2 : $dig3vi is Digit 3rd value index  
          $inputs[3] = $dig3vi; //2 is saved in 3rd index  
   $dig2 = ($dig3v / 10); //value like 10.2 : $dig2 is Digit 2  
     $dig2v = floor($dig2); //It will make 10 : $dig2v is Digit 2nd Value  
       $dig2vi = ($dig2v % 10); // as Mode of 10 is 0 : $dig2vi is Digit 2nd value index  
         $inputs[2] = $dig2vi; //0 is saved in 2rd index  
   $dig1 = ($dig2v / 10); //value like 1.0 : $dig1 is Digit 1  
     $dig1v = floor($dig1); //It will make 1 : $dig1v is Digit 1st Value  
       $inputs[1] = $dig1v; //1 is saved in 1st index  
 if (($inputs[0]>=10000)&&($inputs[0]<=99999))  
   {       
       if(($inputs[1]==$inputs[5])&&($inputs[2]==$inputs[4]))  
         {  
           echo "{$inputs[0]} is a palindrome number. <br />";  
         }  
       elseif(($inputs[1]!=$inputs[5])||($inputs[2]!=$inputs[4]))  
         {  
           echo "{$inputs[0]} is not a palindrome number. <br />";  
         }                                          
   }                           
 else  
   {  
     echo "Try Again : Enter 5 Digit Number. :(";  
   }  
 ?>  
Share this article :

Post a Comment

Give your reviews about this blog. Leave your comments. what do you think about this post?

Comments Description is given below:
1) I love to read comments, but do not spam.
2) Like this blog and also tweet its posts.
3) You can use some xHTML tags.
4) All Comments are Do Follow, Please try to use blog professionally.
5) Mention Your Name below the comment.
6) You can also suggest for improvement.
7) Do not forget to subscribe Samee Articles blog.

---------------------------------------
Thanks for visiting QWC.Me.
==========================================
For free guidelines contact me on SEO Expert | Samee Ullah Feroz is online there.
==========================================
Best Regards

 
Support : | Internet Marketing Specialist And Business Developer
Copyright © 2013-2016. Samee Articles - All Rights Reserved
Proudly powered by Blogger