title: Using file_get_contents to different URLs in a loop seems to break the rest of the code
body: <p>I am currently trying to fetch some facebook data, which I then want to access in Javascript. Specifically, I am trying to access some characteristics of the user's friends.
  So I am getting the user's friend list using file_get_contents to his graph API URL.
  This provides me with an array of friend ids.</p>
  
  <p>As I need a characteristic from each friend, I am doing:</p>
  
  <pre><code>foreach($dataarray as $friend) {
  $friendurl = "https://graph.facebook.com/".$friend-&gt;id."?access_token=".$token."";
  $fdata = json_decode(file_get_contents($friendurl));
  if($fdata-&gt;gender == "male") {
   array_push($fulldata, $fdata-&gt;name);
      }
  }
  </code></pre>
  
  <p>Having this code piece seems to break the javascript code, as none of my alert instructions are ran.</p>
  
  <p>Also, inserting a break after the if, so that only one file_get_contents is done, seems to make the code runnable (but I obviously need to go through all of the friends).</p>
  
  <p>How can I solve this?</p>
  
  <p>I would use jQuery or xmlHttpRequest to do the HTTP GET, but somehow I always seem to get back a status code of 0, with an empty response.</p>
  
  <p>Edit:
  Here is the JS code:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
          function initialize() {
  
                  alert('Test1');
                  &lt;?php
  
                  $fulldata = array();
  
                  $data = $result-&gt;data;
  
                  foreach($data as $friend) {
                      $friendurl = "https://graph.facebook.com/".$friend-&gt;id."?access_token=".$token."";
                      //echo("alert(\"".$friendurl."\");");
                      $fdata = json_decode(file_get_contents($friendurl));
                      if($fdata-&gt;hometown-&gt;name) {
                          array_push($fulldata, $fdata-&gt;hometown-&gt;name);
                      }
                  }
                  echo ("alert(\"".count($fulldata)."\")");
                  ?&gt;
  
                  }
           &lt;/script&gt;
  </code></pre>
  
  <p>I should've also added that this is being done on a page embedded into facebook using the canvas feature.</p>