class exchange_rates public function curl url ch curl_init url curl_se

 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
class exchange_rates {
public function curl($url) {
$ch = curl_init($url);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_COOKIEJAR, dirname(__FILE__).'/cookie.txt');
curl_setopt ($ch, CURLOPT_COOKIEFILE, dirname(__FILE__).'/cookie.txt');
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 60);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_HEADER, 1);
curl_setopt ($ch, CURLOPT_ENCODING, 'utf-8');
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($ch, CURLOPT_HTTPHEADER, array(
));
$result = curl_exec($ch);
curl_close($ch);
$this->result = $result;
return $result;
}
public function parse_money($curl) {
$pattern = "/(?:<td><big>)(.*?)(?:<\/big>)/";
preg_match_all($pattern, $curl, $matches);
return $matches;
}
}
$rates = new exchange_rates();
$curl = $rates->curl('http://finance.i.ua/');
$matches = $rates->parse_money($curl);
preg_match_all($pattern, $curl, $matches);
echo 'Покупка: USD=' . $matches[1][0] . '; EU=' . $matches[1][3];
echo '; RUB=' . $matches[1][6] . "\n";
echo 'Продажа: USD=' . $matches[1][1] . '; EU=' . $matches[1][4];
echo '; RUB=' . $matches[1][7] . "\n";