Hello guys
i have a problem with PHP code and i dont know what is wrong
i want to get the content of a website then search for specific tags then take the value of tags , lets say i want to search for example for these tags
<div class="text platinum">15Platinum</div>
<div class="text gold">64 Gold</div>
<div class="text silver">178 Silver</div>
<div class="text bronze">637 Bronze</div>
and get the value in bold and red
i wrote i simple php code
and every time i run the site i got this error
Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: Input is not proper UTF-8, indicate encoding ! in Entity, line: 22 in C:\AppServ\www\datap\test.php on line 21
Fatal error: Call to a member function getElementsByTagName() on a non-object in C:\AppServ\www\datap\test.php on line 30
what should i do ??
<?php
$url = 'http://us.playstation.com/playstation/psn/profiles/hawkiq';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.15) Gecko/20080623 Firefox/2.0.0.15") );
curl_setopt($ch, CURLOPT_NOBODY, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result= curl_exec ($ch);
curl_close ($ch);
$pregArray = array('/Bronze/', '/Silver/', '/Gold/', '/Platinum/', '/text/','/\%/', '/\s/');
/* The name of the div classes/ids that we need to get data from */
$valuesToLoad = array('text', 'leveltext', 'progresstext', 'text bronze', 'text silver', 'text gold', 'text platinum');
/* Set up our DOM and load the HTML */
$dom = new DOMDocument();
$dom->recover = true;
$dom->strictErrorChecking = false;
$dom->loadHTML($result);
$channel=$dom->getElementsByTagName('text platinum')->item(0);
// just to tets if there is output :(
echo $channel ;
__parse();
function __parse() {
foreach ($dom->getElementsByTagName('div') as $element) {
foreach ($element->attributes as $key => $node) {
foreach ($valuesToLoad as $value) {
if ($element->getAttribute($key) == $value) {
$varName = $value == "text" ? "total_trophies" : preg_replace($pregArray, '', $value);
$varName = preg_replace($pregArray, '', $element->nodeValue);
}
}
}
}
}
?>