actuele-valuta-omrekenen

Gesponsorde koppelingen

PHP script bestanden

  1. actuele-valuta-omrekenen

« Lees de omschrijving en reacties

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
    <title>Actuele Valuta Omrekener  -- Jason de Ridder</title>
</head>

<body>
    <p style="font-size: .9em">
        Koersen komen van
        <a     href="http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml"
            style="color:red;">
                The European Central Bank
        </a>
    </p>
    <h1>
        Bereken een actuele koers vanuit de &euro;<strong> EURO </strong>&euro;
    </h1>
    <p>
        Laatst bewerkt op:<br />
        <?php
        $xmlfile
= file_get_contents('http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml');
        preg_match("/Cube time=[\",'](.*)[\",']/i", $xmlfile, $pubdate);
        $pubdate = explode('-', $pubdate[1]);
        $pubdate = array_reverse($pubdate);
        $pubdate = implode('-', $pubdate);
        echo $pubdate.
    '</p>';
    $array_names = array(
                    'Amerikaanse Dollar',
                    'Japanse Yen',
                    'Bulgaarse Lev',
                    'Cyperse Pond',
                    'Tjechiesche Kroon',
                    'Deense Kroon',
                    'Estlandse Kroon',
                    'Engelse Pond',
                    'Hongaarse Florijn',
                    'Lithuanian Lats',
                    'Letse Lats',
                    'Maltese Lira',
                    'Poolse Zloty',
                    'Nieuw Romenese Leu',
                    'Zweedse Kroon',
                    'Slowaakse Kroon',
                    'Zwitserse Frank',
                    'Ijslandse Kroon',
                    'Noorweegse Kroon',
                    'Kroatse Kuna',
                    'Russiche Roebel',
                    'Nieuw Turkse Lieren',
                    'Australische Dollar',
                    'Canadese Dollar',
                    'Chinese Yuan Renminbi',
                    'Hong Kong Dollar',
                    'Indonesische Rupiah',
                    'Zuid Koreaanse Won',
                    'Maleisische Ringgit',
                    'Nieuw Zeelandse Dollar',
                    'Filippijnse Peso',
                    'Singaporese Dollar',
                    'Thaise Baht',
                    'Zuid Afrikaanse Rand'
                );
    ?>

    <form action="" method="post">
        <fieldset>
            <legend>
                Bereken koers!
            </legend>
            <table summary="formholder">
                <tr>
                    <td>&euro; <input type="text" name="waarde" value="<?php if(isset($_POST['waarde'])) { echo $_POST['waarde']; } else { echo '1,00'; } ?>" id="waarde" /></td>
                </tr>
                <tr>
                    <td>
                        <select name="currency">
                            <?php
                            echo '<option value=""';
                            if(    !isset($_POST['currency']) ||
                                empty($_POST['currency'])) {
                                    echo ' selected="selected"';
                                }

                            echo '>Maak hieronder uw keuze:</option>';
                            echo "\n\t\t\t\t\t\t\t".'<option value="2.20371"';
                            if(    isset($_POST['currency']) &&
                                $_POST['currency'] == '2.20371') {
                                      echo ' selected="selected';
                            }

                            echo '>Nederlandse Gulden</option>';
                            preg_match_all("/Cube currency=[\",'](.{3})[\",']/i", $xmlfile, $currency);
                            preg_match_all("/Cube currency=[\",'].*[\",'] rate=[\",'](.*)[\",']/i", $xmlfile, $rate);
                            foreach($currency[1] as $key => $valuta) {
                                    echo "\n\t\t\t\t\t\t\t".'<option value="'.$rate[1][$key].'"';
                                    if(    isset($_POST['currency']) &&
                                        $_POST['currency'] == $rate[1][$key]) {
                                              echo ' selected="selected"';
                                    }

                                    echo '>'.$array_names[$key].'</option>';
                            }

                            ?>


                        </select>
                    </td>
                </tr>
                <tr>
                    <td>
                        <input type="submit" value="Bereken!" />
                    </td>
                </tr>
            </table>
        </fieldset>
    </form>
    <?php
    if($_SERVER['REQUEST_METHOD'] === "POST") {
        $waarde = str_replace(',', '.', $_POST['waarde']);
        if(!is_numeric($waarde)) {
            echo '<p style="color:red;">Uw waarde is niet nummeriek!</p>';
        }

        else {
            if(    !empty($_POST['currency']) &&
                in_array($_POST['currency'], $rate[1])) {
                    echo '<p style="font-size: 2em; color:blue;">';
                    echo '&euro; '.$_POST['waarde'].
                         ' x '.str_replace('.',',', $_POST['currency']).
                         ' = <strong>'.
                         str_replace('.',
                                      ',',
                                      round(
                                          $_POST['waarde'] * $_POST['currency'],
                                          2
                                      )
                                     ).

                         '</strong></p>';
            }
        }
    }

    ?>

    
</body>
</html>

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.