Solved

feet and inches to inches

Posted on 2013-11-24
3
354 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

717 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