title: get json from a URL in php
body: <p>I understand this is a common question.I want to know how do I fetch JSON from url in php.</p>
  
  <p><strong>the below file is where the .php file is :</strong></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;html&gt;
  &lt;head&gt;
      &lt;?php
      // $url = "https://localhost:8666/web1/popupData/dataWeekly.php";
      // $emp = file_get_contents($url);
  
      $json_url = "https://localhost:8666/web1/popupData/dataWeekly.php";
      $json = file_get_contents($json_url);
      $emp = json_decode($json, TRUE);
  
  
  
      ?&gt;
      &lt;script type="text/javascript" src="https://code.jquery.com/jquery-3.1.1.min.js"&gt;&lt;/script&gt;
      &lt;script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.js"&gt;&lt;/script&gt;
  
       &lt;link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.css"&gt;
  
      &lt;script type="text/javascript"&gt;
      $(document).ready(function(){
          var JSON = &lt;?php echo json_encode($emp); ?&gt;;
  
          $('.details').click(function(){
              var name = $(this).attr('id');
  
              $('#dialog').html('&lt;p&gt;Name : ' + name + '&lt;/p&gt; &lt;p&gt;Dept : ' + JSON[name]['dept'] + '&lt;/p&gt; &lt;p&gt;Age : ' + JSON[name]['age'] + '&lt;/p&gt;');
              $('#dialog').dialog();
          });
      })
      &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;!-- Dialog Box --&gt;
  &lt;div style="display: none;" id="dialog"&gt;&lt;/div&gt;
  &lt;!-- Dialog Box --&gt;
  
  &lt;?php
      foreach($emp as $key =&gt; $record)
      {
      ?&gt;
          &lt;ul id="&lt;?php echo $key ?&gt;" class="details"&gt;
              &lt;li&gt;Name: &lt;?php echo $key ?&gt;&lt;/li&gt;
              &lt;li&gt;Dept: &lt;?php echo $record['dept'] ?&gt;&lt;/li&gt;
          &lt;/ul&gt;
      &lt;?php
      }
  ?&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>this is the current errors that I am getting as I run the above php file :</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>Warning: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol in C:\xampp\htdocs\web1\popupData\mp.php on line 8
  
  Warning: file_get_contents(): Failed to enable crypto in C:\xampp\htdocs\web1\popupData\mp.php on line 8
  
  Warning: file_get_contents(https://localhost:8666/web1/popupData/dataWeekly.php): failed to open stream: operation failed in C:\xampp\htdocs\web1\popupData\mp.php on line 8
  
  Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\web1\popupData\mp.php on line 39</code></pre>
  </div>
  </div>
  </p>
  
  <p>please help.</p>