Description
Need to convert miles to feet, or feet to mile or even inches? Using this function you can convert one to the other.
Parameters
curlen
A int, or float length in feet, inches or miles.
type
A string of the type of curlen "i", "f" or "m".
totype
What you would like to convert type to "i", "f" or "m".
on
Turns on or off output of "IN, FT or MI" (1=on, 2=off).
Function
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?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 doesn't have any comments.

