Reputation: 133
I have a strange problem with this class. If I use a local file like test.html the code work perfectly without any errors but if I use remote page like google.com I got this error:
Call to a member function find() on a non-object
I don't understand why this happens nor hw to resolve it
Here is the code
<?php
include('simple_html_dom.php');
$id="hawkiq"; // any PSN id like : ashiqiraqi,duck360...etc
$url='http://www.yourgamercards.net/profile/'.$id; // url for profile page.
$html = new simple_html_dom();
$html->load_file($url);
$img = $html->find('img[alt='.$id.']',0); // Get User image .
foreach($html->find('span.about1me') as $e)
$about= $e->outertext; // Get comment field .
foreach($html->find('td.tlevel') as $e)
$s= $e->innertext;
$level=strip_tags($s); // Get level
foreach($html->find('td.platbg') as $e)
$s= $e->innertext ;
$platinum=strip_tags($s); // Get Platinum Trophies number .
foreach($html->find('td.goldbg') as $e)
$s= $e->innertext ;
$gold=strip_tags($s); // Get Gold Trophies number .
foreach($html->find('td.silverbg') as $e)
$s= $e->innertext ;
$silver=strip_tags($s); // Get Silver Trophies number .
foreach($html->find('td.bronzebg') as $e)
$s= $e->innertext ;
$bronze=strip_tags($s); // Get Bronze Trophies number .
foreach($html->find('td.totaltrophies') as $e)
$s= $e->innertext ;
$total=strip_tags($s); // Get Total trophies
// Under construction :) .
// foreach($html->find('p.statsbottomcard') as $e)
// $s= $e->innertext ;
// $s=strip_tags($s);
// echo $s;
// Table for showing the results .
echo '<table width="71%" border="1" align="center" cellpadding="1" cellspacing="0" bordercolor="#0066CC">
<tr>
<td width="4%" bgcolor="#E1E1E1"><div align="center"><img src="rank.png" width="16" height="16" /></div></td>
<td width="3%" bgcolor="#E1E1E1"><div align="center"><img src="unk.png" width="16" height="11" /></div></td>
<td width="4%" bgcolor="#E1E1E1"><div align="center"><img src="60c562b0cf2ada61af5a7a0c48cf7e55.png" width="25" height="25" /></div></td>
<td width="33%" bgcolor="#E1E1E1"><div align="center" class="style1">Username ( PSN ID ) </div></td>
<td width="8%" bgcolor="#E1E1E1"><div align="center"><img src="25_level.png" width="25" height="25" /></div></td>
<td width="5%" bgcolor="#FEBE7D"><div align="center"><img src="25_bronze.png" width="25" height="25" /></div></td>
<td width="5%" bgcolor="#C3C3C3"><div align="center"><img src="25_silver.png" width="25" height="25" /></div></td>
<td width="6%" bgcolor="#F2BF5D"><div align="center"><img src="25_gold.png" width="25" height="25" /></div></td>
<td width="5%" bgcolor="#6D82AF"><div align="center"><img src="25_platinum.png" width="25" height="26" /></div></td>
<td width="12%" bgcolor="#E1E1E1"><div align="center"><img src="total.png" width="35" height="30" /></div></td>
<td width="15%" bgcolor="#E1E1E1"><div align="center"><img src="points.png" width="16" height="16" /></div></td>
</tr>
<tr>
<td bgcolor="#F2F2F2" class="style1"><div align="center"><strong>1</strong></div></td>
<td bgcolor="#F2F2F2"><div align="center"><img src="kw.png" width="16" height="11" /></div></td>
<td bgcolor="#F2F2F2"><div align="center">'.$img.'</div></td>
<td bgcolor="#F2F2F2" class="style1"><div align="center" class="style4">
<div align="center"><a href="#" class="style5">'.$id.'</a><br>'.$about.'</div>
</div></td>
<td bgcolor="#F2F2F2" class="style1"><div align="center">'.$level.'</div></td>
<td bgcolor="#FEBE7D" class="style1"><div align="center">'.$platinum.'</div></td>
<td bgcolor="#C3C3C3" class="style1"><div align="center">'.$gold.'</div></td>
<td bgcolor="#F2BF5D" class="style1"><div align="center">'.$silver.'</div></td>
<td bgcolor="#6D82AF" class="style1"><div align="center">'.$bronze.'</div></td>
<td bgcolor="#F2F2F2" class="style1"><div align="center">'.$total.'</div></td>
<td bgcolor="#F2F2F2" class="style1"><div align="center">not implemented</div></td>
</tr>';
?>
Upvotes: 0
Views: 3039
Reputation: 6992
That error basically means you're trying to call find() on $html->find but $html is not the object
<?php
include('simple_html_dom.php');
$id="hawkiq"; // any PSN id like : ashiqiraqi,duck360...etc
$url='http://www.yourgamercards.net/profile/'.$id; // url for profile page.
$html = new simple_html_dom();
//here $html is now object if this will not work use $html = file_get_html($url); this will work for you surely
$html = $html->load_file($url);
$img = $html->find('img[alt='.$id.']',0); // Get User image .
foreach($html->find('span.about1me') as $e)
$about= $e->outertext; // Get comment field .
foreach($html->find('td.tlevel') as $e)
$s= $e->innertext;
$level=strip_tags($s); // Get level
foreach($html->find('td.platbg') as $e)
$s= $e->innertext ;
$platinum=strip_tags($s); // Get Platinum Trophies number .
foreach($html->find('td.goldbg') as $e)
$s= $e->innertext ;
$gold=strip_tags($s); // Get Gold Trophies number .
foreach($html->find('td.silverbg') as $e)
$s= $e->innertext ;
$silver=strip_tags($s); // Get Silver Trophies number .
foreach($html->find('td.bronzebg') as $e)
$s= $e->innertext ;
$bronze=strip_tags($s); // Get Bronze Trophies number .
foreach($html->find('td.totaltrophies') as $e)
$s= $e->innertext ;
$total=strip_tags($s); // Get Total trophies
// Under construction :) .
// foreach($html->find('p.statsbottomcard') as $e)
// $s= $e->innertext ;
// $s=strip_tags($s);
// echo $s;
// Table for showing the results .
echo '<table width="71%" border="1" align="center" cellpadding="1" cellspacing="0" bordercolor="#0066CC">
<tr>
<td width="4%" bgcolor="#E1E1E1"><div align="center"><img src="rank.png" width="16" height="16" /></div></td>
<td width="3%" bgcolor="#E1E1E1"><div align="center"><img src="unk.png" width="16" height="11" /></div></td>
<td width="4%" bgcolor="#E1E1E1"><div align="center"><img src="60c562b0cf2ada61af5a7a0c48cf7e55.png" width="25" height="25" /></div></td>
<td width="33%" bgcolor="#E1E1E1"><div align="center" class="style1">Username ( PSN ID ) </div></td>
<td width="8%" bgcolor="#E1E1E1"><div align="center"><img src="25_level.png" width="25" height="25" /></div></td>
<td width="5%" bgcolor="#FEBE7D"><div align="center"><img src="25_bronze.png" width="25" height="25" /></div></td>
<td width="5%" bgcolor="#C3C3C3"><div align="center"><img src="25_silver.png" width="25" height="25" /></div></td>
<td width="6%" bgcolor="#F2BF5D"><div align="center"><img src="25_gold.png" width="25" height="25" /></div></td>
<td width="5%" bgcolor="#6D82AF"><div align="center"><img src="25_platinum.png" width="25" height="26" /></div></td>
<td width="12%" bgcolor="#E1E1E1"><div align="center"><img src="total.png" width="35" height="30" /></div></td>
<td width="15%" bgcolor="#E1E1E1"><div align="center"><img src="points.png" width="16" height="16" /></div></td>
</tr>
<tr>
<td bgcolor="#F2F2F2" class="style1"><div align="center"><strong>1</strong></div></td>
<td bgcolor="#F2F2F2"><div align="center"><img src="kw.png" width="16" height="11" /></div></td>
<td bgcolor="#F2F2F2"><div align="center">'.$img.'</div></td>
<td bgcolor="#F2F2F2" class="style1"><div align="center" class="style4">
<div align="center"><a href="#" class="style5">'.$id.'</a><br>'.$about.'</div>
</div></td>
<td bgcolor="#F2F2F2" class="style1"><div align="center">'.$level.'</div></td>
<td bgcolor="#FEBE7D" class="style1"><div align="center">'.$platinum.'</div></td>
<td bgcolor="#C3C3C3" class="style1"><div align="center">'.$gold.'</div></td>
<td bgcolor="#F2BF5D" class="style1"><div align="center">'.$silver.'</div></td>
<td bgcolor="#6D82AF" class="style1"><div align="center">'.$bronze.'</div></td>
<td bgcolor="#F2F2F2" class="style1"><div align="center">'.$total.'</div></td>
<td bgcolor="#F2F2F2" class="style1"><div align="center">not implemented</div></td>
</tr>';
?>
Upvotes: 1
Reputation: 9858
You don't need to assign the return value of the load_file()
method to variable. The following code should work just fine
$html = new simple_html_dom();
$html->load_file($url); // No need to assign the return value to a variable, instead just use $html as you normally would.
// Rest of the code here...
Upvotes: 0