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
https://forums.phpfreaks.com/topic/91252-can-some-one-help-me-on-this/
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.

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);
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.