Logo
Feet, Miles, And Inches Converter
Online Now: 0
Snippet Code
Need to convert miles to feet, or feet to mile or even inches? Using this function you can convert one to the other.
<?php
function distance($curlen,$type,$totype,$on){
    
//Check to see if the first value is an interger
    
if(!is_int($curlen)){
        return 
'Wrong input type for first value';
        exit;
    }
    
//Make sure second value is either f,i, or m
    
if($type!="f"&&$type!="i"&&$type!="m"){
        return 
'Wrong input type for second value';
        exit;
    }
    
//Make sure third value is either f,i, or m
    
if($totype!="f"&&$totype!="i"&&$totype!="m"){
        return 
'Wrong input type for third value';
        exit;
    }
    
//Make sure fourth value is either 1 or 2
    
if($on!=1&&$on!=2){
        return 
'Wrong input type for fourth value';
        exit;
    }
    
//If it passes the above, get the current type
    
switch($type){
        
//if it is an i do the math
        
case "i":
            if(
$totype=="f"){
                
$len $curlen 12;
                if(
$on==1){
                    return 
number_format(round($len,1)).' FT';
                }else{
                    return 
number_format(round($len,1));
                }
            }elseif(
$totype=="m"){
                
$len $curlen 63360;
                if(
$on==1){
                    return 
number_format(round($len,1)).' MI';
                }else{
                    return 
number_format(round($len,1));
                }
            }
        break;
        
//if it is an f do the math
        
case "f":
            if(
$totype=="i"){
                
$len $curlen 12;
                if(
$on==1){
                    return 
number_format(round($len,1)).' IN';
                }else{
                    return 
number_format(round($len,1));
                }
            }elseif(
$totype=="m"){
                
$len $curlen 5280;
                if(
$on==1){
                    return 
number_format(round($len,1)).' MI';
                }else{
                    return 
number_format(round($len,1));
                }
            }
        break;
        
//if it is an m do the math
        
case "m":
            if(
$totype=="i"){
                
$len $curlen 63360;
                if(
$on==1){
                    return 
number_format(round($len,1)).' IN';
                }else{
                    return 
number_format(round($len,1));
                }
            }elseif(
$totype=="f"){
                
$len $curlen 5280;
                if(
$on==1){
                    return 
number_format(round($len,1)).' FT';
                }else{
                    return 
number_format(round($len,1));
                }
            }
        break;
    }
}

//position 1 = distance numaric numbers only no commas
//position 2 = current lenght type of position 1
//position 3 = convert lenght type of position 1 and 2
//position 4 = FT,MI,IN extentions on or off :: 1=on : 2=off
//m = miles
//f = feet
//i = inches
echo distance(123,"m","f",1);
?>
 
Snippet Comments

Add Your Comment

avandia lawyer
2011-06-27 21:08:20
This is one of the best converters that you can use. IT works so good. I have been using it for a while with no problems.
office 2010
2011-06-14 00:06:09
I am glad to find your impressive way of writing the post. Now it become easy for me to understand and implement the concept. Thanks for sharing the post.
Supra For Sale
2011-06-13 23:38:15
General Holiefield, the United Auto Workers’ Chrysler Division Vice-President together with Chrysler and government officials has regarded the plant as a sign that Cerberus has faith in the automaker’s turnaround plan.
call center technology
2011-03-31 11:31:46
This snippet is very useful. It makes a lot of sense to reuse PHP code snippets. Why reinvent the wheel every time we need a function that has been developed previously. There are plenty of other coding issues to spend our time on!
Bill E.
2011-03-28 19:21:15
This is a great snippet. I am working on a application that involves
concrete moisture
2011-03-03 07:06:17
When we do estimate for concrete jobs, we often have to do conversions like this. I am assembling a series of tools to use on our smart phones to help make remote estimations easier. This is a great snippet for me to add to this tool.
nick
2011-02-23 21:27:18
a very useful code. it would be easy for me now to convert mile to feet or feet to mile. kabbalah
php scripts
2010-09-14 00:21:06
so nice a script. thx.

Add Your Comment

 
Snippet Tools
Rate this Snippet:

Rate the difficulty level:

Request Snippet Update


Suggested Difficulty Level: Advanced
Current Score: 2.74
Total votes: 301
Total Views: 7525

Other top snippets by admin:

1. JPEG to ASCII Converter
2. Add (th, st, nd, rd, th) to the end of a number
3. Dynamic Page Content From Links
4. AJAX Quickie
5. Simple Image CAPTCHA

Search
Search for:







User Panel

User name:

Password:

Register And Post Your Own Snippets

New Snippets

1.  Shorten text and (4 of 1)

2.  file-based simple guest (0 of 0)

3.  adding an entry (0 of 0)

4.  integer to currency (1.33 of 3)

5.  Aggregate IP addresses (0 of 0)

6.  file handling (0 of 0)

7.  testing system with (0 of 0)

8.  Make an php (1 of 1)

9.  allow download in (5 of 1)

10.  redirect in 3 (0 of 0)

11.  live clock with (0 of 0)

12.  visit counter (3.5 of 2)

13.  contact form with (4 of 1)

14.  show a specific (0 of 0)

15.  The & sign (0 of 0)

16.  static variable in (0 of 0)

17.  multiplication table with (0 of 0)

18.  function with multiplicationt (0 of 0)

19.  php generated menu (0 of 0)

20.  drawing a table (0 of 0)

21.  embedded array (one (0 of 0)

22.  checks the week (0 of 0)

23.  put links on (4.5 of 2)

24.  Directory Image Gallery (0 of 0)

25.  TOS (4 of 1)

Home | Forum | Free PHP Web Hosting | Contact | Terms & Conditions |  
Donate
PHPSnips.com - ©2012 Amethyst Creative