-
Notifications
You must be signed in to change notification settings - Fork 2
/
currency_converter.inc.php
104 lines (96 loc) · 2.45 KB
/
currency_converter.inc.php
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
<?php
/*
CURRENCYCONVERTER
Date - Feb 23,2005
Author - Harish Chauhan
Email - [email protected]
ABOUT
This PHP script will use for conversion of currency.
you can find it is tricky but it is usefull.
*/
Class CURRENCYCONVERTER
{
var $_amt=1;
var $_to="";
var $_from="";
var $_error="";
function CURRENCYCONVERTER($amt=1,$to="",$from="")
{
$this->_amt=$amt;
$this->_to=$to;
$this->_from=$from;
}
function error()
{
return $this->_error;
}
function convert($amt=NULL,$to="",$from="")
{
if ($amt == 0) {
return 0;
}
if($amt>1)
$this->_amt=$amt;
if(!empty($to))
$this->_to=$to;
if(!empty($from))
$this->_from=$from;
//$host="www.iraqidinar.org";
$host="www.xe.com";
$fp = @fsockopen($host, 80, $errno, $errstr, 30);
if (!$fp)
{
$this->_error="$errstr ($errno)<br />\n";
return false;
}
else
{
//$file="/conversiontool2.asp";
$file="/ucc/convert.cgi";
//$str = "?amount=".$this->_amt."&ConvertFrom=".$this->_from."&ConvertTo=".$this->_to;
$str = "?language=xe&Amount=".$this->_amt."&From=".$this->_from."&To=".$this->_to;
$out = "GET ".$file.$str." HTTP/1.0\r\n";
$out .= "Host: $host\r\n";
$out .= "Connection: Close\r\n\r\n";
@fputs($fp, $out);
while (!@feof($fp))
{
$data.= @fgets($fp, 128);
}
@fclose($fp);
@preg_match("/^(.*?)\r?\n\r?\n(.*)/s", $data, $match);
$data =$match[2];
$search = array ("'<script[^>]*?>.*?</script>'si", // Strip out javascript
"'<[\/\!]*?[^<>]*?>'si", // Strip out HTML tags
"'([\r\n])[\s]+'", // Strip out white space
"'&(quot|#34);'i", // Replace HTML entities
"'&(amp|#38);'i",
"'&(lt|#60);'i",
"'&(gt|#62);'i",
"'&(nbsp|#160);'i",
"'&(iexcl|#161);'i",
"'&(cent|#162);'i",
"'&(pound|#163);'i",
"'&(copy|#169);'i",
"'&#(\d+);'e"); // evaluate as php
$replace = array ("",
"",
"\\1",
"\"",
"&",
"<",
">",
" ",
chr(161),
chr(162),
chr(163),
chr(169),
"chr(\\1)");
$data = @preg_replace($search, $replace, $data);
@preg_match_all("/(\d[^\.]*(\.\d+)?)/",$data,$mathces);
$return=preg_replace("/[^\d\.]*/","",$mathces[0][4]);
return (double)$return;
}
}
}
?>