WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Weight Conversion Calculator
Categories : PHP, Algorithms, Regexps Click here to Update Your Picture
Murray Moffatt
Date : Feb 13th 2005
Grade : 1 of 5 (graded 1 times)
Viewed : 2848
File : 4077.php
Images : No Images for this code example.
Search : More code by Murray Moffatt
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

<?php
/*
  Description: Weight Conversion Calculator

  Author: Murray Moffatt for A Web 4 U Designs

  Notes: Originally written for use on CarolynGibson.com

  History:
    2003-04-?? : Initial coding.
    2005-02-13 : Remove extra CarolynGibson.com HTML and make
      stand-alone for publishing on WeberDev.com.
    2005-02-16 : Get $step from $_POST and add a Go Back link.
*/
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Weight Conversion</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="author" content="A Web 4 U Designs - www.aweb4u.co.nz">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<h3>Weight Conversion</h3>
<?php
$step
= $_POST["step"];
if (
$step == "") {
?>
<p>You can use this on-line calculator to convert your weight measurements
  from kilograms to pounds or from pounds to kilograms.</p>
<p>Do you want to convert from metric to imperial (kilograms to pounds)
  or imperial to metric (pounds to kilograms)?</p>
<form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post" name="unitsForm" id="unitsForm">
  <table border="0" cellspacing="1" cellpadding="2">
    <tr>
      <td align="left"><input name="units" type="radio" value="metric" checked>
        Metric to Imperial</td>
    </tr>
    <tr>
      <td align="left"><input type="radio" name="units" value="imperial">
        Imperial to Metric</td>
    </tr>
    <tr>
      <td><input type="submit" name="Submit" value="Next ->">
        <input name="step" type="hidden" id="step" value="1">
      </td>
    </tr>
  </table>
</form>
<?php
}
if (
$step == "1") {
 
$units = $_POST["units"];
?>
<p>Type the weight you want to convert into the box below:</p>
<form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post" name="inputForm" id="inputForm">
  <table border="0" cellspacing="1" cellpadding="2">
    <tr>
      <td align="right"><b>Weight:</b></td>
      <td align="left"><input name="weight" type="text" id="weight" size="6" maxlength="6">
        <?php if ($units == "metric") echo " kilograms"; else echo "pounds"; ?>
      </td>
    </tr>
    <tr>
      <td><input name="step" type="hidden" id="step" value="2">
        <input name="units" type="hidden" id="units" value="<?php echo $units; ?>">
      </td>
      <td><input type="submit" name="Submit" value="Next ->">
      </td>
    </tr>
  </table>
</form>
<?php
}
if (
$step == "2") {
 
$units = $_POST["units"];
 
$weight = $_POST["weight"];

  if (!
IsValidNumber($weight, ".", 2, 1, 999)) {
    echo
"<p>The weight measurement you entered, \"$weight\", is invalid.<br>";
    echo
"Please enter a number between 1 and 999, optionally with up to two decimal places.<br>";
    echo
"For example <b>90.5</b> is 90 and a half, <b>105.25</b> is 105 and a quarter.</p>";
    echo
"<p>Please press Back on your browser and try again.</p>";
    die(
"</body></html>");
  }
 
  if (
$units == "metric") {
?>
<p>The weight of <?php echo $weight; ?> kilograms equals <b><?php echo round(($weight * 2.2046), 2); ?></b> pounds
  (<b><?php echo round(($weight * 0.157473), 2); ?></b> stones).</p>
<?php
 
} else {
?>
<p>The weight of <?php echo $weight; ?> pounds equals <b><?php echo round(($weight * 0.4536), 2); ?></b> kilograms.</p>
<?php
 
}
?>
<p><a href="<?php echo $_SERVER["PHP_SELF"]; ?>">Go Back</a></p>
<?php
}

function
IsValidNumber($number, $decimal = null, $dec_prec = null, $min = null, $max = null) {
  if (
is_array($number)) {
   
extract($number);
  }
 
$dec_prec   = $dec_prec ? "{1,$dec_prec}" : '+';
 
$dec_regex  = $decimal  ? "[$decimal][0-9]$dec_prec" : '';
  if (!
preg_match("|^[-+]?\s*[0-9]+($dec_regex)?\$|", $number)) {
    return
false;
  }
  if (
$decimal != '.') {
   
$number = strtr($number, $decimal, '.');
  }
 
$number = (float)$number;
  if (
$min !== null && $min > $number) {
    return
false;
  }
  if (
$max !== null && $max < $number) {
    return
false;
  }
  return
true;
}
?>
</body>
</html>



Calculate Body Mass Index
Categories : PHP, Algorithms, Regexps
PHP Script to find url links in a page
Categories : PHP, URLs, Regexps, Arrays
Tag content retrieval from websites with preg_match
Categories : PHP, Regexps, Arrays, HTML and PHP
Check parameters validity. Paranoia was designed to check the validity of the parameters that a php page will receive after a form submission. It can be used to check the variables sent by POST or GET
Categories : Algorithms, HTML and PHP, PHP, Variables
A very simple way to build and do a hierarchical html categories browser without javascript , just using html php and mySql
Categories : HTML and PHP, Databases, Algorithms, PHP, MySQL
This script is a contact form between users of a website (kinda like the PM function on the forums)
Categories : PHP, Databases, MySQL, Regexps
Simple way to replace a variable value in a .conf (.ini) file using a webbrowser - the first stage of a complete universal configuration editor
Categories : PHP, Regexps, Code Editors, Filesystem
ereg -- Regular expression match
Categories : PHP, PHP Functions, Regexps
Gets the browser and OS from the $_SERVER['http_user_agent'] variable in PHP
Categories : PHP, HTTP, Regexps
Boolean Keyword Interpreter
Categories : PHP, Algorithms, Search Engines
I need a trim function/regexp that will trim all " " from the ends of a string.
Categories : Regexps, PHP, Strings
Diffusion-Limited Aggregation visualization
Categories : PHP, Graphics, Algorithms, Math.
Check for functional file links (broken Files)
Categories : PHP, Data Validation, FTP, Regexps, Arrays
Browse a MySQL database & draw a tree view & load final items into a template page.
Categories : MySQL, Complete Programs, Algorithms, PHP, Databases
Recursive function to move files on a filesystem. It can be minor changed in order to copy recursively.
Categories : PHP, Filesystem, Algorithms