Hot File

Creating applications with PHP currency exchange and Google Finance

View: 377    Dowload: 0   Comment: 0   Post by: hanhga  
Author: none   Category: References   Fields: Other

0 point/8 review File has been tested

There are many financial companies or real estate when web design requirements, generally requires items to display rate of currency rates as well as functionality that allows viewers to visit their website can manually switch unit currency according to the latest exchange rate.

Introduction

There are many financial companies or real estate when web design requirements, generally requires items to display rate of currency rates as well as functionality that allows viewers to visit their website can manually switch unit currency according to the latest exchange rate. If you are wondering how they did not know through this article, I will share with you the code in PHP help you can create such applications right on your website or blog.

To illustrate the application, we need to create 2 files index.php and convert.php.

Index.php

This file will contain a list of the currency to be converted and a need to change the value input box.

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
include "convert.php";
$from       = isset($_POST['from']) ? $_POST['from'] : '';
$to         = isset($_POST['to']) ? $_POST['to'] : '';
$amount     = isset($_POST['amount']) ? $_POST['amount'] : '';
$content = "";
if($_POST){
    if(!is_numeric($amount)){
    $content .= "<br><span style='background-color:red;padding:5px;color:#fff;'>Invalid amount.</span>";
    }
    elseif($from == $to){
    $content .= "<br><span style='background-color:red;padding:5px;color:#fff;'>Please select distinct currencies.</span>";
    }
    else{
    $rawData = currencyConvert($from,$to,$amount);
    $regex  = '#\<span class=bld\>(.+?)\<\/span\>#s';
    preg_match($regex, $rawData, $converted);
    $result = $converted[0];
    if($result == ""){
        $content .= "<br><span style='background-color:red;padding:5px;color:#fff;'>Exchange Rate not available.</span>";
    }
    else{
        $content .= "<br><span style='background-color:lime;padding:5px;'>".$amount." ".$from." = ".$result."</span>";
    }
    }
}
$listFrom = '
<select name="to">
<option  value="AED">United Arab Emirates Dirham (AED)</option>
<option  value="EUR">Euro (€)</option>
<option  value="GBP">British Pound Sterling (£)</option>
<option  value="INR">Indian Rupee (Rs.)</option>
<option  value="PKR">Pakistani Rupee (PKR)</option>
<option  value="SGD">Singapore Dollar (SGD)</option>
<option  value="USD">US Dollar ($)</option>
</select>
';
 
$listTo = '
<select name="to">
<option  value="AED">United Arab Emirates Dirham (AED)</option>
<option  value="EUR">Euro (€)</option>
<option  value="GBP">British Pound Sterling (£)</option>
<option  value="INR">Indian Rupee (Rs.)</option>
<option  value="PKR">Pakistani Rupee (PKR)</option>
<option  value="SGD">Singapore Dollar (SGD)</option>
<option  value="USD">US Dollar ($)</option>
</select>
';
$listFrom  = str_replace("\"$from\"","\"$from\" selected",$listFrom); // Make dropdown selected
$listTo    = str_replace("\"$to\"","\"$to\" selected",$listTo); // Make dropdown selected
 
$content .='<form action="" method="post" name="f">
<input name="amount" maxlength="12" size="5" autocomplete="off" value="'.$amount.'"><br />
<div>
'.$listFrom.'
</div>
<div style="padding: 6px 8px">to</div>
<div>
'.$listTo.'
</div>
<input type=submit value="Convert">
</form>';
?>

convert.php

This is the key of the article, you copy the entire code below and paste it into this file to perform the currency conversion process.

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
<?php
function currencyConvert($from,$to,$amount){
 
    $url = "http://www.google.com/finance/converter?a=$amount&from=$from&to=$to";
 
    $request = curl_init();
    $timeOut = 0;
    curl_setopt ($request, CURLOPT_URL, $url);
    curl_setopt ($request, CURLOPT_RETURNTRANSFER, 1);
 
    curl_setopt ($request, CURLOPT_USERAGENT,"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
    curl_setopt ($request, CURLOPT_CONNECTTIMEOUT, $timeOut);
    $response = curl_exec($request);
    curl_close($request);
 
    return $response;
}
?>

Ham currencyConvert will receive 3 parameters and sent to Google Finance using HTTP and it will return results. I hope that through this article, you will have experience in using Google finance as well as have an app or your website or blog.

Good luck!

Creating applications with PHP currency exchange and Google Finance

Creating applications with PHP currency exchange and Google Finance Posted on 03-08-2015  There are many financial companies or real estate when web design requirements, generally requires items to display rate of currency rates as well as functionality that allows viewers to visit their website can manually switch unit currency according to the latest exchange rate. 5/10 377

Comment:

To comment you must be logged in members.

Files with category

  • Instructions for installing and configuring Windows Live Mail on Windows 10 simple

    View: 2286    Download: 0   Comment: 0   Author: none  

    Instructions for installing and configuring Windows Live Mail on Windows 10 simple

    Category: References
    Fields: Other

    0/2 review
    Windows 10 pre-installed Mail application for managing personal email on the device. The latest version of this application but improved a lot and support other email accounts such as Gmail or Yahoo Mail but users almost no "salty" really with this...

  • Step by step instructions to create social networking buttons with CSS3

    View: 1772    Download: 0   Comment: 0   Author: none  

    Step by step instructions to create social networking buttons with CSS3

    Category: References
    Fields: Other

    0.75/6 review
    CSS3 help web designers have the ability to create buttons (buttons) very nice, today I will share with you two tips decoration for button in your web becomes radiant beauty that no need to use photoshop.

  • You should understand the CSS Box Shadow

    View: 1945    Download: 0   Comment: 0   Author: none  

    You should understand the CSS Box Shadow

    Category: References
    Fields: Other

    1.3181818181818/11 review
    Effects his shadow was introduced in the previous article, however, in this article, I will guide more specific about shadow attributes, you try it with anything. First we try to learn css following paragraph:

  • How to do button movement with beautiful CSS3

    View: 1627    Download: 0   Comment: 0   Author: none  

    How to do button movement with beautiful CSS3

    Category: References
    Fields: Other

    0/3 review
    Previously to create motion effects button, you must draw the button in photoshop, then switched to flash to make it possible to move. But now you need not spend too much time doing it, all because of the emergence of CSS3.

  • Create a dropdown menu with CSS3 effects with beautiful transtions

    View: 1908    Download: 0   Comment: 0   Author: none  

    Create a dropdown menu with CSS3 effects with beautiful transtions

    Category: References
    Fields: Other

    0.45/10 review
    More of the dropdown menu you want to introduce to you, this will have the effect menu transitions (converted background of menu background from pale to dark). This menu works well on browsers like FF, Chrome, Safary, but unfortunately did not work...

  • How to hack css for all browsers you should know

    View: 1545    Download: 0   Comment: 0   Author: none  

    How to hack css for all browsers you should know

    Category: References
    Fields: Other

    1.6875/8 review
    In the process of web design, which makes it the most headaches is how to design web pages that you can run on the browser. Especially when clients use the old as IE6 browser such. However, with this article, you will easily edit interface runs well...

  • Create Accordion with extremely beautiful CSS3

    View: 1917    Download: 0   Comment: 0   Author: none  

    Create Accordion with extremely beautiful CSS3

    Category: References
    Fields: Other

    0.9/5 review
    Accordion is a technique that helps you shortened the content that you want displayed on the website. It is often used for the display of submenus. In addition you can also use it for content, images. Before applying this procedure, you have to use...

  • Create the effect Hovercho images with Webkit and CSS3 is great

    View: 1638    Download: 0   Comment: 0   Author: none  

    Create the effect Hovercho images with Webkit and CSS3 is great

    Category: References
    Fields: Other

    1.125/4 review
    WebKit is one open source application framework provides the necessary components built one for your web browser. Along with CSS3, cả have contributed to very nice effect những previously only using JavaScript or JQuery thực beige.​

 
Newsletter Email

File suggestion for you

File top downloads

logo codetitle
Codetitle.com - library source code to share, download the file to the community
Copyright © 2015. All rights reserved. codetitle.com Develope by Vinagon .Ltd