e-solat php script


/ Published in: PHP
Save to your folder(s)

The purpose of this code is to grab information from e-solat.gov.my and get payer exact time.


Copy this code and paste it in your HTML
  1. <?php
  2. /* --------------------------------------------
  3. Malaysia Prayer time (e-Solat.gov.my)
  4. --------------------
  5. Data source : http://www.e-solat.com.my
  6. Author : Fazlee Rezuan [[email protected]]
  7. version : 2.1
  8. Description : Sila tukar kod kawasan didalam value 'Kod Kawasan' atau
  9. guna parameter seperti 'http://solat.dynamiclabs.my/JHR01'.
  10. Pastikan ada file .htaccess di dalam direktori yang sama.
  11.  
  12. .htaccess
  13. ======== Start ==========
  14. RewriteEngine on
  15. RewriteBase /
  16. RewriteCond %{SCRIPT_FILENAME} !-d
  17. RewriteCond %{SCRIPT_FILENAME} !-f
  18. RewriteRule ^(.*)$ index.php?kod=$1 [QSA]
  19. ========== End ========
  20.  
  21.  ----------------------------------- */
  22.  
  23. // Kod Kawasan
  24. if($_GET['kod'] == ''){ $kod_kawasan = 'SGR01'; }
  25. else { $kod_kawasan = $_GET['kod']; }
  26.  
  27. $area = array(
  28. 'JHR01' => 'Pulau Aur dan Pemanggil',
  29. 'JHR02' => 'Kota Tinggi, Mersing, Johor Bahru',
  30. 'JHR03' => 'Kluang dan Pontian',
  31. 'JHR04' => 'Batu Pahat, Muar, Segamat, Gemas',
  32. 'KDH01' => 'Kota Setar, Kubang Pasu, Pokok Sena',
  33. 'KDH02' => 'Pendang, Kuala Muda, Yan',
  34. 'KDH03' => 'Padang Terap, Sik',
  35. 'KDH04' => 'Baling',
  36. 'KDH05' => 'Kulim, Bandar Bahru',
  37. 'KDH06' => 'Langkawi',
  38. 'KDH07' => 'Gunung Jerai',
  39. 'KTN01' => 'K.Bharu,Bachok,Pasir Puteh,Tumpat,Pasir Mas,Tnh. Merah,Machang,Kuala Krai,Mukim Chiku',
  40. 'KTN03' => 'Jeli, Gua Musang (Mukim Galas, Bertam)',
  41. 'MLK01' => 'Bandar Melaka, Alor Gajah, Jasin, Masjid Tanah, Merlimau, Nyalas',
  42. 'NGS01' => 'Jempol, Tampin',
  43. 'NGS02' => 'Port Dickson, Seremban, Kuala Pilah, Jelebu, Rembau',
  44. 'PHG01' => 'Pulau Tioman',
  45. 'PHG02' => 'Kuantan, Pekan, Rompin, Muadzam Shah',
  46. 'PHG03' => 'Maran, Chenor, Temerloh, Bera, Jerantut',
  47. 'PHG04' => 'Bentong, Raub, Kuala Lipis',
  48. 'PHG05' => 'Genting Sempah, Janda Baik, Bukit Tinggi',
  49. 'PHG06' => 'Bukit Fraser, Genting Higlands, Cameron Higlands',
  50. 'PLS01' => 'Kangar, Padang Besar, Arau',
  51. 'PNG01' => 'Seluruh Negeri Pulau Pinang',
  52. 'PRK01' => 'Tapah,Slim River dan Tanjung Malim',
  53. 'PRK02' => 'Ipoh, Batu Gajah, Kampar, Sg. Siput dan Kuala Kangsar',
  54. 'PRK03' => 'Pengkalan Hulu, Grik dan Lenggong',
  55. 'PRK04' => 'Temengor dan Belum',
  56. 'PRK05' => 'Teluk Intan, Bagan Datoh, Kg.Gajah,Sri Iskandar, Beruas,Parit,Lumut,Setiawan dan Pulau Pangkor',
  57. 'PRK06' => 'Selama, Taiping, Bagan Serai dan Parit Buntar',
  58. 'PRK07' => 'Bukit Larut',
  59. 'SBH01' => 'Zon 1 - Sandakan, Bdr. Bkt. Garam, Semawang, Temanggong, Tambisan',
  60. 'SBH02' => 'Zon 2 - Pinangah, Terusan, Beluran, Kuamut, Telupit',
  61. 'SBH03' => 'Zon 3 - Lahad Datu, Kunak, Silabukan, Tungku, Sahabat, Semporna',
  62. 'SBH04' => 'Zon 4 - Tawau, Balong, Merotai, Kalabakan',
  63. 'SBH05' => 'Zon 5 - Kudat, Kota Marudu, Pitas, Pulau Banggi',
  64. 'SBH06' => 'Zon 6 - Gunung Kinabalu',
  65. 'SBH07' => 'Zon 7 - Papar, Ranau, Kota Belud, Tuaran, Penampang, Kota Kinabalu',
  66. 'SBH08' => 'Zon 8 - Pensiangan, Keningau, Tambunan, Nabawan',
  67. 'SBH09' => 'Zon 9 - Sipitang, Membakut, Beaufort, Kuala Penyu, Weston, Tenom, Long Pa Sia',
  68. 'SGR01' => 'Gombak,H.Selangor,Rawang, H.Langat,Sepang,Petaling, S.Alam',
  69. 'SGR02' => 'Sabak Bernam, Kuala Selangor, Klang, Kuala Langat',
  70. 'SGR03' => 'Kuala Lumpur',
  71. 'SGR04' => 'Putrajaya',
  72. 'SWK01' => 'Zon 1 - Limbang, Sundar, Terusan, Lawas',
  73. 'SWK02' => 'Zon 2 - Niah, Belaga, Sibuti, Miri, Bekenu, Marudi',
  74. 'SWK03' => 'Zon 3 - Song, Belingan, Sebauh, Bintulu, Tatau, Kapit',
  75. 'SWK04' => 'Zon 4 - Igan, Kanowit, Sibu, Dalat, Oya',
  76. 'SWK05' => 'Zon 5 - Belawai, Matu, Daro, Sarikei, Julau, Bitangor, Rajang',
  77. 'SWK06' => 'Zon 6 - Kabong, Lingga, Sri Aman, Engkelili, Betong, Spaoh, Pusa, Saratok, Roban, Debak',
  78. 'SWK07' => 'Zon 7 - Samarahan, Simunjan, Serian, Sebuyau, Meludam',
  79. 'SWK08' => 'Zon 8 - Kuching, Bau, Lundu,Sematan',
  80. 'SWK09' => 'Zon 9 - Zon Khas',
  81. 'TRG01' => 'Kuala Terengganu, Marang',
  82. 'TRG02' => 'Besut, Setiu',
  83. 'TRG03' => 'Hulu Terengganu',
  84. 'TRG04' => 'Kemaman Dungun',
  85. 'WLY02' => 'Labuan'
  86. );
  87.  
  88. if(!$area) { $area_title = $area[$kod_kawasan]; } else { $area_title = $area[$_GET['kod']]; }
  89.  
  90.  
  91. $value = strip_tags(file_get_contents('http://www2.e-solat.gov.my/solat.php?kod='.$kod_kawasan.'&lang=BM'));
  92.  
  93.  
  94. $stripped_value = preg_replace('/\s+/',' ',$value);
  95. $waktu = explode('WaktuSolat', str_replace('&nbsp;', ' ', $stripped_value));
  96. $waktu1 = ereg_replace("[^0-9: ]", "", $waktu[1]);
  97. $solat = explode(' ', str_replace(' ',' ', $waktu1));
  98. $strip_waktu = explode(" ", $waktu[0]);
  99.  
  100. $waktu_solat = array(
  101. 'Imsak' => $strip_waktu[(array_search('Imsak', $strip_waktu)+1)],
  102. 'Subuh' => $strip_waktu[(array_search('Subuh', $strip_waktu)+1)],
  103. 'Syuruk' => $strip_waktu[(array_search('Syuruk', $strip_waktu)+1)],
  104. 'Zohor' => $strip_waktu[(array_search('Zohor', $strip_waktu)+1)],
  105. 'Asar' => $strip_waktu[(array_search('Asar', $strip_waktu)+1)],
  106. 'Maghrib' => $strip_waktu[(array_search('Maghrib', $strip_waktu)+1)],
  107. 'Isyak' => $strip_waktu[(array_search('Isyak', $strip_waktu)+1)]
  108. );
  109.  
  110. foreach ($waktu_solat as $nama_waktu => $jam_waktu) {
  111. $solat_time .= $nama_waktu.": ".@date('g:ia', @strtotime($jam_waktu)).", ";
  112. }
  113.  
  114. ?>
  115. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  116. <html lang="en">
  117. <head>
  118. <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
  119. <title>Watu Solat <?php echo $area_title; ?></title>
  120. <meta name="description" content="<?php echo $solat_time; ?>">
  121. <meta name="author" content="Fazlee Rezuan">
  122. </head>
  123. <body>
  124. <h3><?php echo $area_title; ?></h3>
  125. <h5><?php echo date('d M Y'); ?></h5>
  126. <?php
  127. foreach ($waktu_solat as $nama_waktu => $jam_waktu) {
  128. echo $nama_waktu.": ".@date('g:ia', @strtotime($jam_waktu))."<br> ";
  129. }
  130. ?>
  131. </body>
  132. </html>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.