0

I am trying to implement parts of an external api found here (http://api.football-data.org/alpha/soccerseasons/) into my wordpress theme.

However I have no idea to get the data from X to Y.

I have tried using this code

$uri = 'http://api.football-data.org/alpha/soccerseasons/354/leagueTable';
$reqPrefs['http']['method'] = 'GET';
$stream_context = stream_context_create($reqPrefs);
$response = file_get_contents($uri, false, $stream_context);
$fixtures = json_decode($response);

echo stripslashes($fixtures);

to no avail as it displays the data as unformated api data with links everywhere....

closed as off-topic by Brian Fegter, TheDeadMedic, Mayeenul Islam, Pieter Goosen, shea Mar 21 '15 at 2:27

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

  • 3
    Try a print recursive print_r($fixtures); echo is for strings, not arrays. – Brian Fegter Mar 18 '15 at 20:45
1

First, I highly recommend you get to know your data model before doing anything. For this purpose I recommend dumping the raw JSON into a linter or formatter (e.g. JSONLint) to see what you're dealing with.

That said, what Brian suggests is appropriate -- you should take a look at the object you produced from json_decode by passing it through print_r. Without knowing exactly what you're up to, it's tough to make any specific recommendations, but since most of the data appears to be embedded within the standing property, I'll give you a contrived example of how you could work through those, rendering a <ul>...</ul> for each standing and an accompanying league caption title:

<h1><?php echo esc_html($fixtures->leagueCaption); ?></h1>
<?php
foreach($fixtures->standing as $standing) {
    ?>
<ul>
    <li><strong>Position:</strong> <?php echo $standing->position; ?></li>
    <li><strong>Team:</strong> <?php echo $standing->position; ?></li>
    <li><strong>Games Played:</strong> <?php echo $standing->playedGames; ?></li>
    <li><strong>Points:</strong> <?php echo $standing->points; ?></li>
    <li><strong>Goals:</strong> <?php echo $standing->goals; ?></li>
    <li><strong>Goals (Against):</strong> <?php echo $standing->goalsAgainst; ?></li>
    <li><strong>Goals (Difference):</strong> <?php echo $standing->goalsDifference; ?></li>
</ul>
    <?php
}
?>

Not the answer you're looking for? Browse other questions tagged or ask your own question.