Solved

feet and inches to inches

Posted on 2013-11-24
3
346 Views
Last Modified: 2013-11-25
turn this feet-inches to inches conversion
$inches = current(explode("'", $height)) * 12 + end(explode("'", rtrim(trim($height), '"')));

to

an object oriented method (not just a procedural function) that accepts feet-inches as a parameter and returns inches
0
Comment
Question by:rgb192
  • 2
3 Comments
 
LVL 20

Accepted Solution

by:
Mark Brady earned 500 total points
ID: 39673581
I think you have already asked this in another question however if you want this done in an object class you just pout it inside a function. Here's a quick example.

<?php

// instantiate the class object
$convert = new Conversion();

// call its run method (function)
$length = "6'3''"; // 6 foot 3 inches

$inches = $convert->feet_to_inches($length);

var_dump($inches);


// the end.....

class Conversion {
    
        
    public function feet_to_inches($length) {
        // explode the string
        $temp = array_map('trim', explode("'", $length));
        
        return ($temp[0] * 12) + $temp[1];
    }
}

?>

Open in new window

0
 

Author Closing Comment

by:rgb192
ID: 39673588
that addition temp[0] (feet) + temp[1] inches makes code easy to understand

thanks
0
 
LVL 20

Expert Comment

by:Mark Brady
ID: 39675417
You're welcome
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now