Showing posts with label feet to meters in php. Show all posts
Showing posts with label feet to meters in php. Show all posts

Tuesday, March 24, 2015

Feet To Meters Solver in PHP

In this simple program it will ask the user to enter a value in feet and then it will convert to its meters equivalent using PHP as our programming language. I also added validation function to check if the text field is empty or not and if the user give not a numeric value it will display an error message to the user informing that the value must be numeric in nature.

If you have some questions please send me an email at jakerpomperada@yahoo.com and jakerpomperada@gmail.com

People here in the Philippines who wish to contact me can reach me at my mobile number 09173084360



Program Listing

<html>
<title> FEET TO METERS SOLVER </title>
<style>
body { 
  font-size:20px; 
  font-family:arial;
  color:blue;
  } 
</style>
<?php
error_reporting(0);

$values = $_POST['value'];

 // function to solve convert feet to meters

 function feet_to_meters($variable) {
           return($variable * 0.3048);
}

if(isset($_POST['check'])) {

     if (ctype_alpha($values)) {
      echo "<script>";  
  echo "alert('PLEASE ENTER A NUMERIC VALUE.');";
  echo "</script>";
  $values="";
 }
 
else if(preg_match('#[^a-zA-Z0-9]#', $values)) {
      echo "<script>";  
  echo "alert('PLEASE ENTER A NUMERIC VALUE.');";
  echo "</script>";
        $values="";
      
}

    else  if ($values=="") {
      echo "<script>";  
  echo "alert('It Cannot Be Empty!!! Please enter a integer value.');";
  echo "</script>";
  $values="";
           }
else { 
      $title = "The equivalent value of ".$values." Feet(s) is " 
          .feet_to_meters($values)." Meter(s).";
       }  
   }  

if(isset($_POST['clear'])) {
  $values=" "; 
  $title=" ";
  
}

?>
<body style='background-color:lightgreen'>
<div style='width:800px;margin:auto'>
  <br> <h1 align="center"> FEET TO METERS SOLVER </h2>
  <br>
<form action="" method="post">
 Enter a Number : <input type="text" name="value"    value="<?php echo $values; ?>" autofocus  size=20/>
   <input type="submit" name="check" value="Convert To Meters" 
  title="Click here to convert to meters equivalent."/>
  <input type="submit" name="clear" value="Clear" 
  title="Click here to clear text box and values on the screen"/>
</form>
<br> 
<?php 
echo $title;
 ?>
  </body>
</html>