2021年1月29日星期五

echo getUrlContent($url) for the last url only

I have a site urls array (php files links) and need to echo each one through a loop but it showed the content of the last url of the loop only! I used getUrlContent($url) function

for ($i=0;$i<sizeof($site_arr);$i++){      echo getUrlContent($site_arr[$i]);      echo '<br>===============================</br>';  }    function getUrlContent($url) {      fopen("cookies.txt", "w");      $parts = parse_url($url);      $host = $parts['host'];      $ch = curl_init();      $header = array('GET /1575051 HTTP/1.1',          "Host: {$host}",          'Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',          'Accept-Language:en-US,en;q=0.8',          'Cache-Control:max-age=0',          'Connection:keep-alive',          'Host:adfoc.us',          'User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36',      );        curl_setopt($ch, CURLOPT_URL, $url);      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);      curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);      curl_setopt($ch, CURLOPT_COOKIESESSION, true);        curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookies.txt');      curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies.txt');      curl_setopt($ch, CURLOPT_HTTPHEADER, $header);      $result = curl_exec($ch);      curl_close($ch);      return $result;  }   

how can I echo content of each url please?

https://stackoverflow.com/questions/65963887/echo-geturlcontenturl-for-the-last-url-only January 30, 2021 at 09:48AM

没有评论:

发表评论