Does the flow of context not display the correct output?

I connect to the API, and as a result, it should loop and output 5 iterations of the results from the checks.

The code

<?php

      $i = 0;

$opts = array(
  'https'=>array(
    'method'=>"POST",
    'header'=>"Accept-language: en\r\n" .
              "Cookie: foo=bar\r\n"
  )
);

$context = stream_context_create($opts);

$fp = fopen('https://ssl.theapidomain.com.au/check.php?domain=testdomain&suffixes=com.au', 'r', false, $context);

    while ($i < 5) {
      fpassthru($fp);
      $out = explode('<br>', $fp);
      echo $out[0];
      echo "<br>";
      echo $out[1];
      echo "<br>";
      echo date('H:i:s');
      echo "<br>";
      $i++;
    }

fclose($fp);

?>

Output

available: testdomain.com.au not available: whoisfailure: Resource ID # 2

16:58:57

Resource ID # 2

16:58:57

Resource ID # 2

16:58:57

Resource ID # 2

16:58:57

Resource ID # 2

16:58:57

He should output this 5 times:

available: testdomain.com.au not available: 16:58:57

It seems that when I echo $ out [0] and [2], it displays the resource identifier and not the information inside (available / not available).

0
source share
1 answer

fread() filepointer $fp, fpassthru(). fread, explode(). $fp, Resource #123.

 $html = fread($fp, 16384);
 $out = explode("<br>", $html);

Btw, . - , . PHP , cURL.

0

Source: https://habr.com/ru/post/1782888/


All Articles