Advertisement
Guest User

Untitled

a guest
Jun 30th, 2015
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. <?php
  2.  
  3. $date_now = date('Y-m-d');
  4.  
  5. $result = $db->query("SELECT * FROM curr WHERE date = '$date_now'");
  6. if($result->num_rows) {
  7. while($row = $result->fetch_array(MYSQLI_ASSOC)) {
  8. $xml = $row['xml'];
  9. }
  10. }
  11. else {
  12. $xml = file_get_contents('http://www.nationalbank.kz/rss/rates_all.xml');
  13. $db->query("INSERT INTO curr (date, xml) VALUES ('$date_now', '$xml')");
  14. }
  15.  
  16. if(count($expltext) > 2) {
  17. $expltext[1] = strtoupper($expltext[1]);
  18. $expltext[2] = strtoupper($expltext[2]);
  19.  
  20. $curr1 = preg_replace('/.+?<title>' . $expltext[1] . '<\/title><pubDate>.+?<\/pubDate><description>(.+?)<\/description>.+/', '$1', $xml);
  21. $curr2 = preg_replace('/.+?<title>' . $expltext[2] . '<\/title><pubDate>.+?<\/pubDate><description>(.+?)<\/description>.+/', '$1', $xml);
  22.  
  23. $curr1 = ($expltext[1] == 'KZT') ? 1 : $curr1;
  24. $curr2 = ($expltext[2] == 'KZT') ? 1 : $curr2;
  25.  
  26. $response = '1' . $expltext[1] . ' = ' . ($curr2 / $curr1) . $expltext[2];
  27. }
  28. else {
  29. $response = '/lazy';
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement