Know about Technology!

Responsive Ads Here

Saturday, February 10, 2018

Live Cricket Score API Free For Php


Live Cricket Score Using API For Php

Introduction :

In my previous post i explained about creating live cricket score  website using cricinfo live cricket score XML data . But the problem with that , It will show only the result after the match , But in this article i will help you to create your own live cricket score website , Which show live cricket score not like the cricinfo XML file . I created the new script using a API which will automatically fetch live cricket score data and show it on the implemented site . I know most of the webmasters don't know how to implement API using Php , For the easy of the webmasters i just developed a Php script using the API , It will help you to implement the API on your site easily .

How to Implement Live Cricket Score API on Your Website :

It is very easy to implement live cricket API on your website or mobile site , To implement the script , You have to know the minimum knowledge about Php programming .
  • First of all you need to create a new Php page on your server and name it "cric.php" .
  • Copy and Paste the script showed below this article to the page you created .
<?php
$content=file_get_contents("http://cricscore-api.appspot.com/csa");
$array = json_decode($content,true);
//echo $array[0]['id'];
$u=$array[0]['id'];
echo '<br/>';
$content=file_get_contents("http://cricscore-api.appspot.com/csa?id=$u");
//echo $content;
$array = json_decode($content,true);
//print_r($array);
//echo '<br/>';
echo $array[0]['de'];
$u=$array[0]['de'];
header('Refresh:10;URL=cric.php');
?>
  • Save the page , Now you need to run the page : example "http://example.com/cric.php" .
  • The above script will show only the score but the script which showed below will show Date , Match Result , Batsman Runs , Etc . 
<div id="displayScore"></div>
<script type="text/javascript">
function getReply(data) {
         document.getElementById("displayScore").innerHTML="";
         document.getElementById("displayScore").innerHTML+=data.match+"<br/>";
         document.getElementById("displayScore").innerHTML+=data.score+"<br/>";
         document.getElementById("displayScore").innerHTML+=data.summary+"<br/>";    
         document.getElementById("displayScore").innerHTML+="Dt: "+data.date+"<br/>";    
}
</script>

 <script type="text/javascript" src="http://json-cricket.appspot.com/score.json?callback=getReply"></script>
  • If you want to show more details about the match , Add the above code in to the "cric.php" and save it .
  • You are Done .
If you got any error after implementing the script on your website , Just add the following Php code before the "?>" Tag . It will hide the error from the page .
error_reporting(0);
This script will help you to show live cricket score on your website or mobile site easy , You can put the script anywhere you like your site . The only one condition is that , You must have a Php enabled server .

No comments:

Post a Comment