Skip to content

Instantly share code, notes, and snippets.

@Longkt
Last active March 15, 2017 08:19
Show Gist options
  • Save Longkt/5a276a980fdfb6047608240d4d05e318 to your computer and use it in GitHub Desktop.
Save Longkt/5a276a980fdfb6047608240d4d05e318 to your computer and use it in GitHub Desktop.
Tien-te
<?php
$file = file_get_contents('http://www.vietcombank.com.vn/ExchangeRates/');
//Lấy dữ liệu
$pattern = '#(?<=id="ctl00_Content_ExrateView">).*(?=</table>)#imsU';
preg_match($pattern, $file, $match);
//Tạo mảng
$pattern = '#<td class="code">(.*)</td><td class="code">(.*)</td><td>(.*)</td><td>(.*)</td><td>(.*)</td>.*</tr>#imsU';
preg_match_all($pattern, $match[0], $matches);
foreach ($matches[1] as $key => $value){
// Cắt các ký tự khoảng trắng còn lại
foreach ($matches[3] as $key3 => $value3) {
$matches[3][$key3] = trim($value3);
}
foreach ($matches[5] as $key5 => $value5) {
$matches[5][$key5] = trim($value5);
}
/* Gán vào 1 mảng ví dụ như sau
* [AUD] => Array (
[0] => AUST.DOLLAR -> tên tiền tệ
[1] => 17,042.97 -> giá mua vào tiền mặt
[2] => 17,145.85 -> giá mua vào chuyển khoản
[3] => 17,298.72 -> giá bán ra (tiền mặt hoặc chuyển khoản)
)
*/
$result[$value][] = $matches[2][$key];
$result[$value][] = $matches[3][$key];
$result[$value][] = $matches[4][$key];
$result[$value][] = $matches[5][$key];
}
echo "<pre>";
print_r($result);
echo "</pre>";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment