跳转到主内容
极星编程网:以代码为星,赴技术山海!

钱币换算 Currency conversion using php and Google calculator api

货币换算 Currency conversion using php and Google calculator api ? 立即学习 “ PHP免费学习笔记(深入) ”; Google is a wonderful ! While most of us use it for searching the web for information , few are aware that it has an inbuilt calculator which can also be used for converting a currency into another . Doing so is really simple , you just type ” AMOUNT CURRENCY_CONVERTING_FROM in CURRENCY_CONVERTING_TO ” and search , the inbuilt calculator will give you the result .For example , if one wants to convert 1 U.S Dollar into Euro , he shall type “1 USD in EUR” . ? 立即学习 “ PHP免费学习笔记(深入) ”; Now lets get to the topic of this post , Google also has a secret calculator API ( http://www.google.com/ig/calculator ) that is usually used for iGoogle gadgets , but since its free and open , anyone can use it . ? 立即学习 “ PHP免费学习笔记(深入) ”; So if you want to convert a currency into another using the API , your callback URL would look like : ? 立即学习 “ PHP免费学习笔记(深入) ”; ? 立即学习 “ PHP免费学习笔记(深入) ”; ? 立即学习 “ PHP免费学习笔记(深入) ”;
www.google.com/ig/calculator?hl=en&q=AMOUNT-FROM_CURRENCY=?TO_CURRENCY // 1 USD in EUR example www.google.com/ig/calculator?hl=en&q=1USD=?EUR
? ? 立即学习 “ PHP免费学习笔记(深入) ”; ? 立即学习 “ PHP免费学习笔记(深入) ”; In the above example , you get a string which looks like " {lhs: "1 U.S. dollar",rhs: "0.838574423 Euros",error: "",icc: true} " . You can easily explode() the string using php and extract the required data . ? 立即学习 “ PHP免费学习笔记(深入) ”; To make things easier for you , here is a simple php function that converts a currency into another using the Google calculator API . This example uses cURL , so you have to have it enabled for this code to work . ? 立即学习 “ PHP免费学习笔记(深入) ”; ? 立即学习 “ PHP免费学习笔记(深入) ”; To make things easier for you , here is a simple php function that converts a currency into another using the Google calculator API . This example uses cURL , so you have to have it enabled for this code to work . ? 立即学习 “ PHP免费学习笔记(深入) ”; ? 立即学习 “ PHP免费学习笔记(深入) ”;
? ? 立即学习 “ PHP免费学习笔记(深入) ”; ? 立即学习 “ PHP免费学习笔记(深入) ”; The value returned by Google usually has 9 decimal places , you can round it off to a no. of digits after decimal of you choice using the round() function . By default the above function rounds the value to 3 digits after decimal . ? 立即学习 “ PHP免费学习笔记(深入) ”; Now here is how you can use the function in your scripts ? 立即学习 “ PHP免费学习笔记(深入) ”; ? 立即学习 “ PHP免费学习笔记(深入) ”; ? 立即学习 “ PHP免费学习笔记(深入) ”;
? ? 立即学习 “ PHP免费学习笔记(深入) ”; ? 立即学习 “ PHP免费学习笔记(深入) ”; Hope this has helped you with converting currencies using php on your website ? 立即学习 “ PHP免费学习笔记(深入) ”; ? 立即学习 “ PHP免费学习笔记(深入) ”; ? 立即学习 “ PHP免费学习笔记(深入) ”; 来源:?http://www.xe.com/ucc/full/?obsolete=yes ? 立即学习 “ PHP免费学习笔记(深入) ”; 附:货币 ? 立即学习 “ PHP免费学习笔记(深入) ”;
? ? 立即学习 “ PHP免费学习笔记(深入) ”; ? 立即学习 “ PHP免费学习笔记(深入) ”; ? 立即学习 “ PHP免费学习笔记(深入) ”; ? 立即学习 “ PHP免费学习笔记(深入) ”; ? 立即学习 “ PHP免费学习笔记(深入) ”; ? 立即学习 “ PHP免费学习笔记(深入) ”; ? 立即学习 “ PHP免费学习笔记(深入) ”;

相关文章