人人商城

calendar.php 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. $url = 'http://www.zdic.net/nongli/' . date('Y-n-j') . '.htm';
  3. $week = array();
  4. $week[0] = '日';
  5. $week[1] = '一';
  6. $week[2] = '二';
  7. $week[3] = '三';
  8. $week[4] = '四';
  9. $week[5] = '五';
  10. $week[6] = '六';
  11. $reply = '今天是 ' . date('Y年n月j日') . ' 星期' . $week[date('w')];
  12. $resp = ihttp_get($url);
  13. if ($resp['code'] == 200 && $resp['content']) {
  14. $content = $resp['content'];
  15. $reply .= "==================\n";
  16. if(preg_match('/<td colspan="2" class="l3">(?P<block>.+?)<\/td>/s', $content, $block)) {
  17. $date = explode('<br>', $block['block']);
  18. array_pop($date);
  19. if(count($date) < 4) {
  20. $shift = array_shift($date);
  21. $year = substr($shift, -9);
  22. array_unshift($date, $year);
  23. array_unshift($date, str_replace($year, '', $shift));
  24. }
  25. $reply .= '农历: ' . implode(' ', $date);
  26. }
  27. if(preg_match('/<td colspan="2" class="ly2">(?P<block>.+?)<\/td>/s', $content, $block)) {
  28. if(preg_match_all('/title=\'(?P<line>.+?)\'/', $block['block'], $lines)) {
  29. $reply .= "==================\n";
  30. $reply .= "宜: \n";
  31. foreach($lines['line'] as $l) {
  32. $reply .= "{$l}\n";
  33. }
  34. }
  35. }
  36. if(preg_match('/<td colspan="4" class="lj2">(?P<block>.+?)<\/td>/s', $content, $block)) {
  37. if(preg_match_all('/title=\'(?P<line>.+?)\'/', $block['block'], $lines)) {
  38. $reply .= "==================\n";
  39. $reply .= "忌: \n";
  40. foreach($lines['line'] as $l) {
  41. $reply .= "{$l}\n";
  42. }
  43. }
  44. }
  45. }
  46. return $this->respText($reply);