Answer the question
In order to leave comments, you need to log in
Why doesn't the Simple HTML DOM function work in a loop?
Such a problem, I copy the list of streams from the site through SimpleHTMLDOM. The problem is that the list is placed on several category pages. Through foreach, I load several categories, but starting from the second iteration, the simple HTML DOM functions do not work.
<?php
include "simple_html_dom.php";
function GetRWGames($rw_cat){
$live = new simple_html_dom();
$live->load_file("http://live.robinwidget.org/static/section" . $rw_cat . ".html");
$data = $live->find(".lshpanel");
$counter = 0;
foreach($data as $game) {
$games[$counter][cat] = $game->find(".section",0)->plaintext;
$games[$counter][time] = $game->find(".date",0)->plaintext;
$temp = $game->find(".lshevent",0)->plaintext;
$temp = explode(" - ", $temp);
$games[$counter][team1] = trim ($temp[0]);
$games[$counter][team2] = trim ($temp[1]);
$temp = $game->find("a");
foreach ($temp as $a) {
$a=$a->href;
if(stristr($a, "javascript:openWindow")==true){
$temp= strstr($a, "http");
$temp= strstr($temp, '"',1);
$games[$counter][links] .= $temp . ";";}
elseif(!strpos($a,"adserving")&&!strpos($a,"adsrv")&&!empty($a))
{$games[$counter][links] .= $a . ";";}
}
$counter++;
}
return $games;
}
$games = array();
// Load HTML from a string
$rw_cats = array(35,36,37,38,39,57,59);
foreach($rw_cats as $rw_cat){
print_r(GetRWGames($rw_cat));
}
Fatal error: Uncaught Error: Call to a member function find() on null in D:\os\OpenServer\domains\newtest.ru\simple_html_dom.php:1113 Stack trace: #0 D:\os\OpenServer\domains\newtest.ru\index.php(7): simple_html_dom->find('.lshpanel') #1 D:\os\OpenServer\domains\newtest.ru\index.php(34): GetRWGames(36) #2 {main} thrown in D:\os\OpenServer\domains\newtest.ru\simple_html_dom.php on line 1113
Answer the question
In order to leave comments, you need to log in
almost the same problem Call to a member function innertext() on null
function getContent($url) {
$html = new simple_html_dom();
$html->load_file($url);
$html->save();
$table = $html->find('table.tb-matches');
foreach ($table as $key => $value) {
foreach ($value->find('tr') as $key => $tr) {
$elem = $tr->find('td', 0);
echo 'key' . $key . '<br>';
echo 'tr' . $tr . '<br>';
echo $tr->find('td', 0)->attr['colspan'] . '----<br>';
}
}
}
foreach ($dateArr as $key => $dateVal) {
getContent($url . $dateVal);
}
foreach ($dateArr as $key => $dateVal) {
$out .= file_get_contents($url . $dateVal) ;
}
$html = new simple_html_dom();
$html->load($out);
$html->save();
$table = $html->find('.list_table');
foreach ($table as $key => $value) {
$dd = $value->attr['date'];
foreach ($value->find('table.tb-matches tr') as $key => $tr) {
$elem = $tr->find('td', 0);
if ($elem->attr['colspan'] != '7') {
$resultArr[$dd][] = array(
'time' => $tr->find('td', 0)->plaintext,
'home_team' => $tr->find('td.home-team', 0)->plaintext,
'away_team' => $tr->find('td.away_team', 0)->plaintext,
'status' => trim($tr->find('td.status', 0)->plaintext),
'score' => $tr->find('td.score', 0)->plaintext,
'href' => 'http://goal24.ru' . $tr->find('td.option a', 0)->href,
);
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question