0

I've already done this once, but cannot for the life of me figure out how I did it. I think it took about 5 lines of code.

I just want to take the array this URL outputs: http://ridetimes.co.uk/queue-times.php and then I would like to loop through the array and output each field.

1
  • this is json format. use json_decode to convert this format to php array. Commented Jul 11, 2013 at 22:01

3 Answers 3

4

you can try

$array = json_decode(file_get_contents("http://ridetimes.co.uk/queue-times.php"), true);

Then for part to to output

<table>
  <thead>
    <tr><th><?= implode("</th><th>", array_map("htmlspecialchars",array_map("ucwords", array_keys($array[0])))) ?></th><tr>
  </thead>
  <tbody>
  <?php foreach($array as $row): ?>
    <tr><td><?= implode("</td><td>", array_map("htmlspecialchars", $row)) ?></td></tr>
  <?php endforeach; ?>
  </tbody>
</table>
Sign up to request clarification or add additional context in comments.

3 Comments

that's 1, pad it and you get paid more :-)
@Dagon That makes it 6 if you count the html :)
Thats what I was after! Cheers!
0

Use json_decode() http://php.net/manual/en/function.json-decode.php

That should help you I would think

Comments

0

You can use file_get_contents and a foreach loop and var_dump to print the contents:

$data= json_decode(file_get_contents("http://ridetimes.co.uk/queue-times.php"), true);
foreach ($data as $row) {
    var_dump($row);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.