Skip to content

Instantly share code, notes, and snippets.

@khaschuluu
Created January 17, 2011 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save khaschuluu/782923 to your computer and use it in GitHub Desktop.
Save khaschuluu/782923 to your computer and use it in GitHub Desktop.
Get cash values from KhanBank.com in php.
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<script src="http://code.jquery.com/jquery-1.4.4.min.js"></script>
</head>
<body>
<table border=1>
<?php
$html = file_get_contents('http://www.khanbank.com/mn/294/%D0%A5%D0%B0%D0%BD%D1%88%D0%B8%D0%B9%D0%BD-%D0%BC%D1%8D%D0%B4%D1%8D%D1%8D.html');
$match_res = preg_match_all('|<td[^>]*><img src=\"([^\"]*)\" border=0> <strong>([A-Z]{3})</strong></td><td align=center >([^<]*)</td><td align=right >([^<]*)</td><td align=right >([^<]*)</td><td align=right >([^<]*)</td><td align=right >([^<]*)</td><td align=right >([^<]*)</td></tr>|U', $html, $matches, PREG_SET_ORDER);
foreach ($matches as $val) {
if ($val[4] != null)
echo "\t<tr>\n\t\t<td><img src=\"" . $val[1] . "\"/></td>\n\t\t<td>" . $val[2] . "</td>\n\t\t<td>" . $val[3] . "</td>\n\t\t<td>" . $val[4] . "</td>\n\t\t<td>" .$val[5] . "</td>\n\t\t<td>" . $val[6] . "</td>\n\t\t<td>" . $val[7] . "</td>\n\t\t<td>" . $val[8] . "</td>\n\t</tr>\n";
}
echo "\n";
?>
</table>
<input type="radio" name="status" value="1" checked="checked" />Албан
<input type="radio" name="status" value="2" />Бэлэн
<input type="radio" name="status" value="3" />Бэлэн бус<br />
<input type="text" name="input" />
<select name="valuit_in">
</select>=>
<select name="valuit_out">
</select>
<input type="button" name="convert" value="Хөрвүүл" />
<div id="valuit"></div>
<script>
var stat = 1;
var valuit_in = {};
valuit_in["MNT"] = {};
valuit_in["MNT"][1] = 1;
valuit_in["MNT"][2] = 1;
valuit_in["MNT"][3] = 1;
valuit_in["MNT"][4] = 1;
valuit_in["MNT"][5] = 1;
<?php
foreach ($matches as $val) {
if ($val[4] != null) {
echo "\n\t\t\tvaluit_in[\"" . $val[2] . "\"] = {};";
echo "\n\t\t\tvaluit_in[\"" . $val[2] . "\"][1] = " . $val[4] . ";";
if ($val[5] != null) echo "\n\t\t\tvaluit_in[\"" . $val[2] . "\"][2] = " . $val[5] . ";";
if ($val[6] != null) echo "\n\t\t\tvaluit_in[\"" . $val[2] . "\"][3] = " . $val[6] . ";";
if ($val[7] != null) echo "\n\t\t\tvaluit_in[\"" . $val[2] . "\"][4] = " . $val[7] . ";";
if ($val[8] != null) echo "\n\t\t\tvaluit_in[\"" . $val[2] . "\"][5] = " . $val[8] . ";";
echo "\n";
}
}
echo "\n";
?>
//$('#valuit').html(valuit_in["USD"][1]);
$.each(valuit_in, function(index, value) {
$('select').append($("<option></option>").attr("value", index).text(index));
});
$('select[name=valuit_in]').change(function() {
$('select[name=valuit_in] option:selected').each(function() {
$('#valuit').html(valuit_in[$(this).text()][1]);
});
}).change();
//$('#valuit').html($('input[name=status]:radio:checked').val());
$('input[name=status]:radio').change(function() {
stat = $('input[name=status]:radio:checked').val();
}).change();
</script>
<br />
Эх сурвалж <a href="http://www.khanbank.com/mn/294/%D0%A5%D0%B0%D0%BD%D1%88%D0%B8%D0%B9%D0%BD-%D0%BC%D1%8D%D0%B4%D1%8D%D1%8D.html">Хаан банк</a>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment