Create a Unit Conversion Application with the Zend_Measure Component

Friday Feb 12th 2010 by Jason Gilmore

Learn how to create a simple conversion calculator using the Zend Framework's Zend_Measure component. Converting between the world's measurement units will never be easier.

The Zend Framework's Zend_Measure component can convert between an enormous number of measurement formats. This useful tool carries out not only typical unit conversions such as between miles and kilometers, but also between a wide variety of scientific formats such as torque, frequency, force, illumination, current, and density.

Of course, performing even relatively simple conversion calculations from memory can be fairly difficult, let alone calculating more esoteric conversions such as from square meters to acres. To automate this conversion process, PHP Guru Jason Gilmore used the Zend Framework and the Zend_Measure component to create a measurement-calculator capable of easily migrating data among the most commonly used formats. In his PHPBuilder tutorial, he shows you how to create your own.

To use the Zend_Measure component, you start by defining the originating unit type and value, and then calling the convertTo() method to convert the value to the desired destination unit type. Therefore, to convert a value from one standard to another, you statically call the respective class constants. Each Zend_Measure class (Zend_Measure_Length, Zend_Measure_Volume, Zend_Measure_Area, etc.) contains a well-organized list of class constants at the top of the file.

Read the full story at PHPBuilder:
Create a Unit Conversion Application with the Zend_Measure Component

Mobile Site | Full Site