Actually, here's the code, I can not understand why the Undefined error is issued variable: mas_cat_child. What am I doing wrong?

//парсинг с помощью phpQuery $pageText =new Curl(); $page=$pageText->get_page(URL); $cat_page = phpQuery::newDocument($page); $paginator = $cat_page->find('table:nth-child(2) > tr >td > a'); foreach ($paginator as $link){ $url=pq($link)->attr('href'); $url = "http://www.site.uz/rus/".$url; $mas_cat_url[]=$url; } //print_r($mas_cat_url); foreach($mas_cat_url as $child_link){ //echo $child_link; $page_child=$pageText->get_page($child_link); $cat_page_child = phpQuery::newDocument($page_child); $line = $cat_page_child->find('table:nth-child(2) > tr'); foreach ($line as $l_link){ //echo $l_link; $ln = pq($l_link)->html(); $mas_cat_child[]=$ln; } print_r($mas_cat_child); 

}

  • I'm learning to do the parsing and there is a page with links that I put in the $ mas_cat_url array. Everything seems to be fine, then, following these links, I open the pages and try to add them to another array and display the rows of the table. I get an error about an undefined variable, I don’t understand why. - ZaurK

1 answer 1

Well, probably because you are trying to manipulate a variable before it is initialized.

 $mas_cat_child[]=$ln; 

Here it tries to access a variable as an array. Where's the ad? Where is the indication that this is an array?

 print_r($mas_cat_child); 

Especially listing. If the line is empty, $ mas_cat_child will not be set here.

  • You know, in the first array $ mas_cat_url [] = $ url; works like the exact same $ mas_cat_child [] = $ ln; Probably all the same line is empty. - ZaurK