PHP 7 Cricbuzz API Example Script to Fetch Live Cricket Score of Matches in Browser Using HTML5 & Javascript

Hello, friend today we are going to see clearly what we are going to see in the article PHP 7 Cricbuzz API Example Script to Fetch Live Cricket Score of Matches in Browser Using HTML5 & Javascript. We hope you find this article very useful.

PHP 7 Cricbuzz API Example Script to Fetch Live Cricket Score of Matches in Browser Using HTML5 & Javascript

PHP 7 Cricbuzz API Example Script to Fetch Live Cricket Score of Matches in Browser Using HTML5 & Javascript

https://cricket-api.vercel.app/cri.php<span class="pl-k">?</span>url=<span class="pl-k"><</span>Live Match URL<span class="pl-k">></span>

git clone https://github.com/mskian/cricket-api.git
<span class="pl-c1">cd</span> cricket-api
<span class="pl-c1">cd</span> cri

php -S localhost:6001

http://localhost:6001/cri.php<span class="pl-k">?</span>url=https://www.cricbuzz.com/live-cricket-scores/30524/53rd-match-indian-premier-league-2020

http://localhost:6001/cri.php<span class="pl-k">?</span>url=https://m.cricbuzz.com/live-cricket-scores/30524/53rd-match-indian-premier-league-2020

{
    <span class="pl-s"><span class="pl-pds">"</span>success<span class="pl-pds">"</span></span>: <span class="pl-c1">true</span>,
    <span class="pl-s"><span class="pl-pds">"</span>livescore<span class="pl-pds">"</span></span>: {
        <span class="pl-s"><span class="pl-pds">"</span>title<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">"</span>Sunrisers Hyderabad vs Mumbai Indians, 56th Match<span class="pl-pds">"</span></span>,
        <span class="pl-s"><span class="pl-pds">"</span>current<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">"</span>SRH - 145<span class="pl-cce">\/</span>0 (16.2)<span class="pl-pds">"</span></span>,
        <span class="pl-s"><span class="pl-pds">"</span>batsman<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">"</span>Wriddhiman Saha*<span class="pl-pds">"</span></span>,
        <span class="pl-s"><span class="pl-pds">"</span>batsmanrun<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">"</span>57<span class="pl-pds">"</span></span>,
        <span class="pl-s"><span class="pl-pds">"</span>ballsfaced<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">"</span>(43)<span class="pl-pds">"</span></span>,
        <span class="pl-s"><span class="pl-pds">"</span>fours<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">"</span>7<span class="pl-pds">"</span></span>,
        <span class="pl-s"><span class="pl-pds">"</span>sixes<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">"</span>1<span class="pl-pds">"</span></span>,
        <span class="pl-s"><span class="pl-pds">"</span>bowler<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">"</span>Nathan Coulter-Nile*<span class="pl-pds">"</span></span>,
        <span class="pl-s"><span class="pl-pds">"</span>bowlerover<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">"</span>3.2<span class="pl-pds">"</span></span>,
        <span class="pl-s"><span class="pl-pds">"</span>bowlerruns<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">"</span>25<span class="pl-pds">"</span></span>,
        <span class="pl-s"><span class="pl-pds">"</span>bowlerwickets<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">"</span>0<span class="pl-pds">"</span></span>,
        <span class="pl-s"><span class="pl-pds">"</span>partnership<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">"</span>145(98)<span class="pl-pds">"</span></span>,
        <span class="pl-s"><span class="pl-pds">"</span>recentballs<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">"</span>Data Not Found<span class="pl-pds">"</span></span>,
        <span class="pl-s"><span class="pl-pds">"</span>lastwicket<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">"</span>... 0 0 4 1 | 0 4 1 1 0 1 | 1 0<span class="pl-pds">"</span></span>,
        <span class="pl-s"><span class="pl-pds">"</span>runrate<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">"</span>CRR: 8.88<span class="pl-pds">"</span></span>,
        <span class="pl-s"><span class="pl-pds">"</span>commentary<span class="pl-pds">"</span></span>: [
            <span class="pl-s"><span class="pl-pds">"</span>16.2 Coulter-Nile to W Saha, no run, 139.1kph, <span class="pl-pds">"</span></span>,
            <span class="pl-s"><span class="pl-pds">"</span>16.1 Coulter-Nile to Warner, 1 run, 124.4kph, length, nipping in off the pitch onto middle. Warner makes room and slaps it to deep point <span class="pl-pds">"</span></span>,
            <span class="pl-s"><span class="pl-pds">"</span>15.5 Pattinson to Warner, no run, 139.7kph, backs away, cuts, but ends up miscuing it back down the pitch <span class="pl-pds">"</span></span>,
            <span class="pl-s"><span class="pl-pds">"</span>15.4 Pattinson to W Saha, 1 run, swivels, one-legged, pulling it to the man in the deep behind square <span class="pl-pds">"</span></span>,
            <span class="pl-s"><span class="pl-pds">"</span>15.3 Pattinson to Warner, 1 run, 118.2kph, back of a length, taking pace off, keeping it outside off for Warner to have to reach out. And he does connect this time, to guide it to third man <span class="pl-pds">"</span></span>,
            <span class="pl-s"><span class="pl-pds">"</span>15.1 Pattinson to Warner, no run, 134.5kph, full, outside off, quick, just inside the tramline. Warner stretches, but can't quite connect <span class="pl-pds">"</span></span>,
            <span class="pl-s"><span class="pl-pds">"</span>14.6 Coulter-Nile to Warner, 1 run, 130.6kph, length, nips back in, and Warner jumps away at the last moment with an opened bat face to steer it through point <span class="pl-pds">"</span></span>,
            <span class="pl-s"><span class="pl-pds">"</span>14.4 Coulter-Nile to Warner, no run, skids through as it seams back in sharply to go under Warner's crouched swat, thudding off his thighs towards backward point <span class="pl-pds">"</span></span>,
            <span class="pl-s"><span class="pl-pds">"</span>14.3 Coulter-Nile to Warner, no run, 136.4kph, serious bouncer, climbing back in. Nope, it's the circumstances that determines its ferocity, and with an 18 runs | 33 balls equation, this is gently left alone <span class="pl-pds">"</span></span>,
            <span class="pl-s"><span class="pl-pds">"</span>14.2 Coulter-Nile to W Saha, 1 run, 136.9kph, full, on middle with the angle-in. Saha goes wristy, through mid-wicket <span class="pl-pds">"</span></span>,
            <span class="pl-s"><span class="pl-pds">"</span>14.1 Coulter-Nile to W Saha, no run, 117kph, in-cutter into the tummy. Saha gets cramped in what looked like an initial attempt to cut, and so drops his wrists, opens his bat face and runs out to short third man <span class="pl-pds">"</span></span>,
            <span class="pl-s"><span class="pl-pds">"</span>13.6 D Kulkarni to Warner, 2 runs, 105.4kph, and very comfortable. Around the fourth-stump, which Warner lines up to and punches through point <span class="pl-pds">"</span></span>,
            <span class="pl-s"><span class="pl-pds">"</span>13.5 D Kulkarni to W Saha, 1 run, 127.6kph, full, on off, quiet flick, long-on <span class="pl-pds">"</span></span>
        ],
        <span class="pl-s"><span class="pl-pds">"</span>teamone<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">"</span>Data Not Found<span class="pl-pds">"</span></span>,
        <span class="pl-s"><span class="pl-pds">"</span>teamtwo<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">"</span>Data Not Found<span class="pl-pds">"</span></span>,
        <span class="pl-s"><span class="pl-pds">"</span>update<span class="pl-pds">"</span></span>: <span class="pl-s"><span class="pl-pds">"</span>Sunrisers Hyderabad need 5 runs in 22 balls<span class="pl-pds">"</span></span>
    }
}

<span class="pl-c">## API Auth and Get data</span>
<span class="pl-k">function</span> <span class="pl-en">display_api_response</span>() {
  <span class="pl-s1"><span class="pl-c1">
lt;/span>base_url</span> = <span class="pl-s">'https://YOUR-API-Domain.com/cri.php?url="</span>;
  <span class="pl-s1"><span class="pl-c1">
lt;/span>score_path</span> = <span class="pl-s">"https://www.cricbuzz.com/live-cricket-scores/30524/53rd-match-indian-premier-league-2020'</span>;
  <span class="pl-s1"><span class="pl-c1">
lt;/span>url</span> = <span class="pl-s1"><span class="pl-c1">
lt;/span>base_url</span>.<span class="pl-s1"><span class="pl-c1">
lt;/span>score_path</span>;
  <span class="pl-s1"><span class="pl-c1">
lt;/span>response</span> = <span class="pl-en">wp_remote_get</span>(<span class="pl-s1"><span class="pl-c1">
lt;/span>url</span>);
  <span class="pl-k">global</span> <span class="pl-s1"><span class="pl-c1">
lt;/span>body</span>;
  <span class="pl-s1"><span class="pl-c1">
lt;/span>body</span> = <span class="pl-en">json_decode</span>( <span class="pl-s1"><span class="pl-c1">
lt;/span>response</span>[<span class="pl-s">'body'</span>], <span class="pl-c1">true</span> );
}
<span class="pl-en">add_action</span>( <span class="pl-s">'init'</span>, <span class="pl-s">'display_api_response'</span> );

<span class="pl-k">var</span> <span class="pl-s1">url</span> <span class="pl-c1">=</span> <span class="pl-s">'https://www.cricbuzz.com/live-cricket-scores/30524/53rd-match-indian-premier-league-2020'</span><span class="pl-kos">;</span>
 
<span class="pl-k">async</span> <span class="pl-k">function</span> <span class="pl-en">fetchscore</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-k">try</span> <span class="pl-kos">{</span>
        <span class="pl-k">const</span> <span class="pl-s1">response</span> <span class="pl-c1">=</span> <span class="pl-k">await</span> <span class="pl-en">fetch</span><span class="pl-kos">(</span><span class="pl-s">'https://api.example.com/cri.php?url="</span> <span class="pl-c1">+</span> <span class="pl-s1">url</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
        <span class="pl-k">const</span> <span class="pl-s1">data</span> <span class="pl-c1">=</span> <span class="pl-k">await</span> <span class="pl-s1">response</span><span class="pl-kos">.</span><span class="pl-en">json</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
        <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s1">data</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span> <span class="pl-k">catch</span> <span class="pl-kos">(</span><span class="pl-s1">exception</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
        <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s">"Connection issue'</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span>
<span class="pl-kos">}</span>
<span class="pl-en">fetchscore</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

git clone https://github.com/mskian/cricket-api.git
<span class="pl-c1">cd</span> cricket-api
<span class="pl-c1">cd</span> cri
php -S localhost:3001

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Deekshi. Here, I post about programming to help developers.

Share on:

Leave a Comment