Jump to content

Can some one help me on this


jeet_0077

Recommended Posts

Hi I am trying to read the contents of the following link:

 

$link = 'http://sports-ak.espn.go.com/broadband/espn360/upcomingEvents';

$content = file_get_contents($link);

$res = json_decode($content, true);

 

the link is returning json out put.

But when I use json_decode function its not returning anything.

 

Can you please tell me what went wrong.

Or can you  please suggest me what has to be done for that.

 

Thanks

Link to comment
Share on other sites

Thanks for the reply..

 

Yes I have json installed on the server.

 

I just got the contents using file_get_contents(). Upto this it works fine.

 

Next I have to get the json return value in an array so that I have  all the values.

 

I used something like:

$var  = json_decode($contents, true);

 

tried to do

print_r($var); but showing nothing.

 

But is should return the array. In subsequent steps when I try to use any index saying that undefined array index.

Link to comment
Share on other sites

There are 2 issues:

 

1) You need to remove the "Events =" off the front of the data

2) There are some special chars in there that the json_decode function does like, specifically: ñ

 

This worked for me:

 

<?php
  $link = 'http://sports-ak.espn.go.com/broadband/espn360/upcomingEvents';
  $content = file_get_contents($link);
  $content = substr($content,strpos($content,'{'));
  $content = utf8_encode($content);
  $res = json_decode($content,true);
  var_export($res);
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.