Flash Website Builder- Trendy Site Builder is a Flash Site Building tool that helps users build stunning websites. Check Out Custom Custom Logo Design by LogoBee. Website Design and Free Logo Templates available.
 CodingForums.com > PHP [tutorial]How To convert units of measurement from one unit or system to another

Before you post, read our: Rules & Posting Guidelines

Enjoy an ad free experience by logging in. Not a member yet? Register.
 05-29-2010, 07:04 AM PM User | #1 is_set New to the CF scene   Join Date: May 2010 Posts: 8 Thanks: 0 Thanked 0 Times in 0 Posts [tutorial]How To convert units of measurement from one unit or system to another Today i will learn you new way to convert units of measurement from one unit or system to another and we will use simple php class first you should download it:Length Class or download the class source code: now how we can use it? For example, we can define the relationship between any unit of length by the number of that length per one meter. PHP Code: ``` 1 m = 100 cm  ``` With this ratio – which we can simply write as 100 – we can easily convert from meters to the new units. We can also convert from the unit cm back to meters by inverting the ratio – 1 / 100.The length class makes use of this simple principal. A data file (length.xml) contains information about each unit of measurement – an abbreviation, a full name, and this ratio. When the ‘length’ is constructed, it converts it from the given unit into the SI unit for length – meters. You can then easily retrieve this length value in any other defined unit type. Example Use If you download the source code, it comes with a file “convert.php.” This isn’t part of the class – it just gives you an example of how to implement the class. Here’s a very simple example to show you the syntax for creating a new length instance and converting a value starting in centimeters to inches. PHP Code: ``` \$len = new length(50, 'cm');echo \$len->getConversion('in') . 'in';  ``` The length constructor takes three arguments – one required and two optional. The first argument is the value of your length (50 in this case). The second parameter is the abbreviation of the unit type (cm). If a unit is not sent, then it is assumed you’re creating a length in meters. The last argument is the path/filename to the “length.xml” data file. It’s assumed to be located in “length.xml” if a path isn’t given. The constructor then converts that value into the standard unit – meters. getConversion() takes one argument – the new unit type. It takes the stored value (in meters) and returns it converted to the unit type you gave.Extending Length to Include Other UnitsThe data file included with the class is by no means intended to be exhaustive. In fact, it’s pretty limited at the moment. I will probably eventually update it with a more or less complete list of units. However, it was created to be easily adaptable by the user. You could even make up new imaginary units (for use in a game, maybe). All you need to do is add a new entry to the xml data file with this format. Code: ``` cm 100 centimeters ```
 05-29-2010, 07:23 AM PM User | #2 firepages Super Moderator   Join Date: May 2002 Location: Perth Australia Posts: 4,035 Thanks: 10 Thanked 92 Times in 90 Posts hmmmm personally I think this is a very long way around a simple problem ... assuming you know the ratios, and (again personally) I cant see any reason to use an XML file with its extra overhead where a simple array would suffice, also posted in the wrong section , will move to snippets if you want. __________________ resistance is... MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)
 05-30-2010, 08:44 AM PM User | #3 is_set New to the CF scene   Join Date: May 2010 Posts: 8 Thanks: 0 Thanked 0 Times in 0 Posts yes i think that to the original programmer made it complex for nothing yes and move it | you have to move it before ask me because that is your froum

 Bookmarks

 Thread Tools Rate This Thread Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home :: Client side development     JavaScript programming         DOM and JSON scripting         Ajax and Design         JavaScript frameworks         Post a JavaScript     HTML & CSS     XML     Flash & ActionScript         Adobe Flex     Graphics and Multimedia discussions     General web building         Site reviews         Building for mobile devices :: Server side development     Apache configuration     Perl/ CGI     PHP         Post a PHP snippet     MySQL         Other Databases     Ruby & Ruby On Rails     ASP     ASP.NET     Java and JSP     Other server side languages/ issues         ColdFusion         Python :: Computing & Sciences     Computer Programming     Computer/PC discussions     Geek News and Humour Web Projects and Services Marketplace     Web Projects         Small projects (quick fixes and changes)         Medium projects (new script, new features, etc)         Large Projects (new web application, complex features etc)         Unknown sized projects (request quote)         Vacant job positions         Looking for work/ for hire         Project collaboration/ partnership         Paid work offers and requests (Now CLOSED)     Career, job, and business ideas or advice     Domains, Sites, and Designs for sale         Domains for sale         Websites for sale         Design templates and graphics for sale :: Other forums     Member Offers     Forum feedback and announcements

All times are GMT +1. The time now is 04:26 AM.