Tuesday, March 20, 2012

prayer time using php and json or php and xml format

0
Xhanch API – Islamic Get Prayer Time is a public API to retrieve a monthly Islamic prayer time based on longitude, latitude, year, month, and gmt. It will returns daily times for fajr, sunrise, zuhr, asr, maghrib, and isha
* ; required; longitude coordinate of a location
* ; required; latitude coordinate of a location
* ; required; year of the prayer time
* ; required; month of the prayer time
* ; required; timezone of a location
* ; xml or json; optional; default is xml; api result mode that you prefer

following are codes will show the timing of uae.

this is Json format:


<?php
$year=date('Y');
$month=date('m');
$day=date('d');

$string= file_get_contents("http://api.xhanch.com/islamic-get-prayer-time.php?lng=55&lat=25&
yy=$year&mm=$month&gmt=4&m=json");
//$json_o=json_decode($string);
$json_a=json_decode($string,true);
//$i=1;
foreach($json_a as $p)
{

echo 'fajr: '.$p[fajr].'<br>';

echo 'zuhr: '.$p[zuhr].'<br>';

echo 'asr: '.$p[asr].'<br>';

echo 'maghrib: '.$p[maghrib].'<br>';

echo 'isha: '.$p[isha].'<br>';
}

?>

this is xml format:

<?php
$doc = new DOMDocument();
$doc->load( 'http://api.xhanch.com/islamic-get-prayer-time.php?lng=55&
lat=25&yy=2012&mm=03&gmt=4' );
$i=0;

foreach($doc->getElementsByTagName("fajr") as $items){

$books = $doc->getElementsByTagName("response");
$fajr=$books->item(0)->getElementsByTagName('fajr')
->item($i)->childNodes->item(0)->nodeValue;
$zuhr=$books->item(0)->getElementsByTagName('zuhr')
->item($i)->childNodes->item(0)->nodeValue;
$maghrib=$books->item(0)->getElementsByTagName('maghrib')
->item($i)->childNodes->item(0)->nodeValue;
$asr=$books->item(0)->getElementsByTagName('asr')
->item($i)->childNodes->item(0)->nodeValue;
$isha=$books->item(0)->getElementsByTagName('isha')
->item($i)->childNodes->item(0)->nodeValue;
$i++;


echo 'fajr:'.$fajr."<br>";
echo 'zuhar:'.$zuhr."<br>";
echo 'asr:'.$maghrib."<br>";
echo 'maghrib:'.$asr."<br>";
echo 'isha:'.$isha."<br>";



}

?>

No comments :

Post a Comment