respiant Posted June 5, 2010 Share Posted June 5, 2010 Hi. I'm making a memberlist for my legion at the online game "Aion". I wanted to find the stats for each member, and yes it worked perfectly, but it took some time for the page to load up.. Take a look at this code: <?php //The $userdata['character'] is from mysql but let's just set it manually.. $userdata['character'] = "Respiant"; $text = file_get_contents('http://uk.aiononline.com/characters/Perento/'. $userdata['character']); $nr = 9; do { $searchfor = '<span class="name"><span>Lv.</span> <em>'. $nr .'</em>'; $pos = strpos($text, $searchfor); if ($pos == true) { $stat = $nr; $nr = 51; } else { $nr++; } } while ($nr < 51); if ($pos != true){ $stat = "<b>Below 10</b>"; } // Okay, on the memberlist it will now say "27" under level on the user "Respiant". Let's just echo it here.. echo "My level is now: <b>". $stat."</b>"; ?> This code goes to http://uk.aiononline.com/characters/Perento/Respiant, reads the sourcecode of the page and is looking for "<span class="name"><span>Lv.</span> <em>" with a number behind, and it stopped when it reached: <span class="name"><span>Lv.</span> <em>27 because I'm level 27. then it made the variable $stat with 27. Is there any better way to do this so the page would load up faster? Please help! Quote Link to comment https://forums.phpfreaks.com/topic/203952-getting-level-stats-from-another-website-help/ Share on other sites More sharing options...
awjudd Posted June 5, 2010 Share Posted June 5, 2010 I would run that script to download stats as a cron job and then store the results in a local database or flat file. I say this because each time the user visits the page, your server is currently putting in the request to the other site which will end up throttling you and use extra bandwidth. ~juddster Quote Link to comment https://forums.phpfreaks.com/topic/203952-getting-level-stats-from-another-website-help/#findComment-1068181 Share on other sites More sharing options...
ignace Posted June 5, 2010 Share Posted June 5, 2010 libxml_use_internal_errors(true); $dom = new DomDocument(); if ($dom->loadHtml('http://uk.aiononline.com/characters/Perento/' . $userdata['character'])) { $xpath = new DomXPath($dom); foreach ($xpath->query('//ul[@class="status"]/li') as $node) { echo $node->childNodes[0]->nodeValue, ': ', $node->childNodes[1]->nodeValue, "<br>\n"; //HP: 1795 (+256) } } Quote Link to comment https://forums.phpfreaks.com/topic/203952-getting-level-stats-from-another-website-help/#findComment-1068194 Share on other sites More sharing options...
respiant Posted June 11, 2010 Author Share Posted June 11, 2010 Now I send all the levels to a mysql database after each update. The site loads really fast up, and they have an option to "update levels" when they want, and they can also see the last update date and time, so I'm happy Quote Link to comment https://forums.phpfreaks.com/topic/203952-getting-level-stats-from-another-website-help/#findComment-1070784 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.