I have raw knowledge of php, I decided to practice with parsing data from the site using phpQuery stopped at the very beginning and have been sorting out the options for quite a long time.
When you run foreach, an error occurs:
Warning: Invalid argument for foreach () in /parser.php on line 13
I read about it, but the problem did not help to solve. Tell me what you need to add, what am I doing wrong?
<?php header('Content-type: text/html; charset=utf-8'); require 'phpQuery.php'; $url='http://ria56.ru/posts/news/'; $file= file_get_contents($url); $doc = phpQuery::newDocument($file); $rianews=$doc->find('.text_posts');//извлекаем только новостные посты $links = $doc->find('.text_posts .name a')->attr('href'); foreach ($doc->find('.name a')->attr('href') as $link){ echo $link.'<br>'; } the library itself is connected as the link was extracted using
$links = $doc->find('.text_posts .name a')->attr('href');