Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Aside from the silly use of strpos(), which you seem to claim was someone else's idea, it seems like you just need to carefully debug.</p> <p>Do something like this:</p> <pre><code>$data = json_decode($json,true); echo "&lt;PRE&gt;"; var_dump($data); die(); </code></pre> <p>Now you can see the data structure the API is giving you. </p> <p>Look at the structure of the array. Notice, for instance, that <code>$data['image_url_large']</code> does not exist. There is, however, <code>$data[0]['channel']['image_url_large']</code>!</p> <p>Notice also that instead of the silly strpos() call, which will give false positives if the string "name" exists anywhere in the json-string, you could do something like:</p> <pre><code>$exists = ! empty($data[0]['name']); </code></pre> <p><strong>EDIT</strong> Here's some code that will hopefully help you on your way:</p> <pre><code> &lt;?php //if you don't do this, you're flying blind. ini_set('display_errors',1); error_reporting(E_ALL); //list.json is a copy of the data from the URL you posted. $json = file_get_contents('./list.json'); //decode the data $data = json_decode($json,true); //uncomment this if you're not sure of what the json's structure is. #echo "&lt;PRE&gt;";var_dump($data);die(); //check for the existence of a "name" key in the first item. $exist = ! empty($data[0]['name']); echo "Exist?:"; if ($exist) { echo " yes\n"; }else{ echo " no\n"; } //output the image url: echo $data[0]['channel']['image_url_large']; //say goodbye die("\n\nAll done.\n"); </code></pre> <p>OUTPUT:</p> <pre><code>$ php test.php Exist?: yes http://static-cdn.jtvnw.net/jtv_user_pictures/beastyqt-profile_image-c5b72ccf47b74ed2-300x300.jpeg All done. </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload