title: php curl help with google url shortner api
body: <p>Im trying to shorten a url using ggole api's.Here is my php code .It gives a blank page when i load</p>
  
  <pre><code>&lt;?php
      define('GOOGLE_API_KEY', 'GoogleApiKey');
      define('GOOGLE_ENDPOINT', 'https://www.googleapis.com/urlshortener/v1');
  
      function shortenUrl($longUrl)
      {
          // initialize the cURL connection
          $ch = curl_init(
              sprintf('%s/url?key=%s', GOOGLE_ENDPOINT, GOOGLE_API_KEY)
          );
  
          // tell cURL to return the data rather than outputting it
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  
          // create the data to be encoded into JSON
          $requestData = array(
              'longUrl' =&gt; $longUrl
          );
  
          // change the request type to POST
          curl_setopt($ch, CURLOPT_POST, true);
  
          // set the form content type for JSON data
          curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
  
          // set the post body to encoded JSON data
          curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($requestData));
  
          // perform the request
          $result = curl_exec($ch);
          curl_close($ch);
  
          // decode and return the JSON response
          return json_decode($result, true);
      }
      if (isset($_POST['url'])) {  
      $url = $_POST['url'];
      $response = shortenUrl('$url');
  
      echo sprintf(
          $response['longUrl'],
          $response['id']
       );
   }
  ?&gt;
  </code></pre>
  
  <p>My html file:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;A BASIC HTML FORM&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;FORM NAME ="form1" METHOD =" " ACTION = "shortner.php"&gt;
  
  &lt;INPUT TYPE = "TEXT" VALUE ="Enter a url to shorten" name="url"&gt;
  &lt;INPUT TYPE = "Submit" Name = "Submit1" VALUE = "Shorten"&gt;
  
  &lt;/FORM&gt;
  &lt;/body&gt;
  &lt;/html
  </code></pre>