Jump to content

Recommended Posts

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!

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

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)  
  }
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.