Showing posts with label reverse a number in php version 2. Show all posts
Showing posts with label reverse a number in php version 2. Show all posts

Thursday, May 4, 2017

Reverse a Number in PHP Version 2

Here is the version 2 of my program reverse a number in PHP what does the program will to is to ask the user to give a number and then it will check if the given number is a palindrome or not a palindrome.  Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.




Sample Program Output


Program Listing

<html>
   
   <head>
      <title>Reverse a Number in PHP </title>
   </head>
   <style>
      
   body {
   font-family:arial;
   font-size:14px;
   font-weight:bold;
   };
   </style>
   
   <body>
      <?php
         error_reporting(0);
                  
         if ($_SERVER["REQUEST_METHOD"] == "POST") {
            $val_1 = test_input($_POST["val_no"]);
          
$num = $val_1;
$p=$num;
$revnum = 0;

while ($num != 0)
{
$revnum = $revnum * 10 + $num % 10;
$num = (int)($num / 10); 
}

if($revnum==$p)
{
echo "\n\n\n";
$result = "The number $p is a Palindrome.";
}
else
{
echo "\n\n\n";
$result = "The number $p is Not a Palindrome.";

}
 
      }
         
         function test_input($data) {
            $data = trim($data);
            return $data;
         }
 
  if ($_POST["clear_me"] == true) {
            $val_1 = "";
$result = "";
           
         }
         
      ?>
      <br>
      <h2>Reverse a Number in PHP</h2>
      <form method = "post" action = "form1.php">
         <table>
            <tr>
               <td>Give a Number </td> 
               <td>&nbsp;<input type = "text" name = "val_no" value="<?php echo $val_1; ?>" autofocus required></td>
            </tr>
                   
            <tr>
               <td>
     <br>
                  <input type = "submit" name = "submit" value = "Check" 
 title="Click here to check if the given number in Palindrome or Not"> &nbsp;&nbsp;&nbsp;
               <input type = "submit" name = "clear_me" value = "Clear"
  title="Click here to clear the textbox."> 
  </td>
            </tr>
         </table>
      </form>
      
      <?php
echo "<br>"; 
echo $result; 
     ?>
    </body>
</html>