title: Microsoft Cognitive Services Bing WebSearch API v5.0
body: <p>I am having some issues with the new Bing search API from Microsoft Azure (cognitive services). Here is my code below, what I am trying to do is call on the API from my form that I have made and simple show results but I am having some trouble doing so, can someone look at my code and see if there are any issues? The error I keep on getting is that I haven't defined the $q variable but I have as you will see in the code. Thanks for the help, appreciate it!</p>
  
  <p>PHP:</p>
  
  <pre><code>&lt;?php
  $accountKey = 'account_key';
  
  $url =  'https://api.cognitive.microsoft.com/bing/v5.0/search?q='.$q.'&amp;count=10&amp;offset=0&amp;mkt=en-us&amp;safesearch=Moderate';
  
  $q = urlencode($_POST['q']);
  
  $opts = array(
    'http'=&gt;array(
    'method'=&gt;"GET",
    'header'=&gt;"Ocp-Apim-Subscription-Key: $accountKey"
    )
  );
  $context = stream_context_create($opts);
  
  // Open the file using the HTTP headers set above
  $file = file_get_contents($url, false, $context);
  $jsonobj = json_decode($file);
  echo $file;
  ?&gt;
  </code></pre>
  
  <p>HTML:</p>
  
  <pre><code>&lt;form method="post" action=""&gt;
  &lt;input name="q" type="text" autocomplete="off" autofocus&gt;
  &lt;input type="submit" name="Search" hidden&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>