Last active
March 15, 2017 08:19
-
-
Save Longkt/5a276a980fdfb6047608240d4d05e318 to your computer and use it in GitHub Desktop.
Tien-te
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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