title: php cURL post to external domain and work with response
body: <p>Ok this may be a simple question. I have a working concept of posting to the external domain and getting it to work with the post to do what i want and need it to do. However. I need it to after doing what I want it to do output a JSON response that I can in turn work with the domain of origin. I know with cURL I should be able to grab whats output but Im not sure how to work it into what I have, as this was initially given to me by someone else to work with and I am not extremely familiar with cURL</p>
  
  <p>this is what I have thus far that works to post to the domain.</p>
  
  <pre><code>$url = 'http://thedomain.com/new/';
          $fields = array(
                      'api'=&gt;'randomkey',
                      'id'=&gt;'100000',
                      'url'=&gt;urlencode($longurl),
                  );
  
      //url-ify the data for the POST
      $fields_string = '?';
      foreach($fields as $key=&gt;$value) { $fields_string .= $key.'='.$value.'&amp;'; }
      rtrim($fields_string,'&amp;');
  
      //open connection
      $ch = curl_init();
  
      //set the url, number of POST vars, POST data
      curl_setopt($ch,CURLOPT_URL,$url);
      curl_setopt($ch,CURLOPT_POST,count($fields));
      curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
  
      //execute post
      $result = curl_exec($ch);
  
      //close connection
      curl_close($ch);
  </code></pre>
  
  <p>how can I alter this to take what the external site would spit out in JSON form and have it so I can work with it from the domain I am working with?</p>