<?php header( 'Content-type: text/html; charset=utf-8' ); set_time_limit(-1); $minViewers = 50; $maxScan = 2000; $filenameRu = 'rusteams.txt'; $filenameAll = 'steams.txt'; // --------------------------------------------- file_put_contents($filenameRu, ''); file_put_contents($filenameAll, ''); for ($offset = 0; $offset <= $maxScan; $offset += 100){ echo "$offset/$maxScan ", PHP_EOL; flush(); ob_flush(); $json = json_decode(file_get_contents("https://twitch.tv/")); foreach ($json->streams as $st){ if ($st->channel->language=='ru' && $st->viewers > $minViewers) file_put_contents($filenameRu, $st->channel->name.PHP_EOL, FILE_APPEND); file_put_contents($filenameAll, $st->channel->name.PHP_EOL, FILE_APPEND); } } // удаляем дубли и сортируем полученные файлы стримов clearAndSort($filenameAll); clearAndSort($filenameRu); echo "[Finished]"; function clearAndSort ($filename){ $steams = file($filename); $steams = array_unique($steams); sort($steams); array_shift($steams); file_put_contents($filename, implode($steams, '')); } 

Warning: Invalid argument for foreach () in Z: \ home \ localhost \ www \ twitch \ tw_get_channels.php on line 23

Closed due to the fact that the issue is too common for participants aleksandr barakin , user194374, Denis Bubnov , Grundy , Denis 14 Dec '16 at 6:49 .

Please correct the question so that it describes the specific problem with sufficient detail to determine the appropriate answer. Do not ask a few questions at once. See “How to ask a good question?” For clarification. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • Wow, tvitch broadcast in wpf application? - Kryshtop
  • one
    Format the code - for example, Ctrl-K. - 0xdb
  • one
    @ivan What's incomprehensible in warning? in $ json-> streams is clearly not something that can be iterated, see what comes in it - Bookin
  • Is " twitch.tv " in JSON format? You have json_decode null. - ilyaplot

1 answer 1

file_get_contents("https://twitch.tv/") gets the HTML, and you are trying to convert this HTML from JSON to an object.
The second mistake is using

 flush(); ob_flush(); 

Without ob_start, and in general it is not clear why.
In general, your code should not work at all.