Nox19
Nox19

Reputation: 35

Pull data from a page and add it to a PHP file

I am trying to create a PHP page which uses data from a page (example: http://services.runescape.com/m=hiscore/index_lite.ws?player=DisplayName). Changing the "DisplayName" to another name changes the value of the numbers shown.

This is the code shown from the page I am trying to pull data from:

665249,1159,37778175 559762,75,1214453 1014682,45,67435 287248,91,6088249 391910,86,3747242 133650,99,13759525 599855,52,125572 264389,94,8032896 -1,1,-1 375977,82,2480819 676548,46,71298 346696,76,1430070 841961,50,105600 843793,41,42078 1178160,20,4481 1092128,32,17847 763021,18,3685 498978,51,121383 485421,53,145460 455992,59,263171 519344,32,17930 -1,1,-1 -1,1,-1 552229,40,37356 -1,1,-1 -1,1,-1 -1,1,-1 -1,0,-1 -1,-1 -1,-1 -1,-1 -1,-1 -1,-1 -1,-1 -1,-1 -1,-1 -1,-1 -1,-1 -1,-1 -1,-1 -1,-1 -1,-1 -1,-1 -1,-1 -1,-1 -1,-1 -1,-1 -1,-1 -1,-1 -1,-1 -1,-1 -1,-1 

Basically, each number corresponds to a value. The format is as follows:

xxx,xxx,xxx xxx,xxx,xxx

The first number represents the position of a player in the hiscores of an ability, the second number represents the level of the corresponding ability, the third number the total experience accumulated in the ability. Successively, there's a space which means that a new ability is being "described" and the format is the same (position,level,experience).

Consequently it could be described as:

position,level,experience position,level,experience position,level,experience

I have tried a few codes found online and tried to tweak them, but I didn't manage to make them work.

Do you know how I could create a working PHP code that can be put in an HTML template?

A better description of the data can be found here: http://services.runescape.com/m=rswiki/en/Hiscores_APIs

Thank you for your help,

Eibe

EDIT:

<?php
header('Content-type: application/json');
require_once 'Runescape_API.class.php';

$rsapi = new Runescape_API;
//Hiscore
if($ressource = $rsapi->getHiscore("Eibe")){
    $result["getHiscore"] = $ressource;
}
//Combat Level
if($ressource = $rsapi->getCombatLevel("Eibe")){
    $result["getCombatLevel"] = $ressource;
}
//Player Clan
if($ressource = $rsapi->getClanByPlayer("Eibe")){
    $result["getClanByPlayer"] = $ressource;
}
//Clan Members
if($ressource = $rsapi->getClanMembers("Loyals")){
    $result["getClanMembers"] = $ressource;
}
//Events
if($ressource = $rsapi->getEvents('archived')){
    $result["getEvents"] = $ressource;
}
//Events By Player
if($ressource = $rsapi->getEventsByPlayer('Eibe','archived')){
    $result["getEventsByPlayer"] = $ressource;
}
//Beast
if($ressource = $rsapi->getBeastById(49)){
    $result["getBeastById"] = $ressource;
}
//Search Beasts
if($ressource = $rsapi->searchBeasts('kuh',1)){
    $result["searchBeasts"] = $ressource;
}
//Beast Cataloque
if($ressource = $rsapi->getBeastCataloque('a',1)){
    $result["getBeastCataloque"] = $ressource;
}
//Area Names
if($ressource = $rsapi->getAreaNames()){
    $result["getAreaNames"] = $ressource;
}
//Beasts area
if($ressource = $rsapi->getBeastsByArea("Bank")){
    $result["getBeastsByArea"] = $ressource;
}
//Slayer names
if($ressource = $rsapi->getSlayerCatNames("Bank")){
    $result["getSlayerCatNames"] = $ressource;
}
//Beasts by slayer cat
if($ressource = $rsapi->getBeastsBySlayerCat(96)){
    $result["getBeastsBySlayerCat"] = $ressource;
}
//memberStatus, returns true|false and null by failure
$ressource = $rsapi->getMemberStatus("Glotzfrosch");
if($ressource !== NULL){
    $result["getMemberStatus"] = $ressource;
}/*
//Quests
if($ressource = $rsapi->getQuests("Glotzfrosch")){
    $result["getQuests"] = $ressource;
}*/
//recent player events
if($ressource = $rsapi->getRecentPlayerEvents("Drumgun")){
    $result["getRecentPlayerEvents"] = $ressource;
}
//item information
if($ressource = $rsapi->getItemInformation(444,"br")){
    $result["getItemInformation"] = $ressource;
}
//item price
if($ressource = $rsapi->getPriceInformation(444,"br")){
    $result["getPriceInformation"] = $ressource;
}
//item cataloque
if($ressource = $rsapi->getItemCataloque(2)){
    $result["getItemCataloque"] = $ressource;
}
//items by cataloque
if($ressource = $rsapi->getItemsByCataloque(12,"a",20)){
    $result["getItemsByCataloque"] = $ressource;
}
//player avatar urls
if($ressource = $rsapi->getPlayerAvatars("Drumgun")){
    $result["getPlayerAvatars"] = $ressource;
}
//news
if($ressource = $rsapi->getNews(2)){
    $result["getNews"] = $ressource;
}
//Hiscore for oldschool runescape
if($ressource = $rsapi->getHiscore07("xMorgan")){
    $result["getHiscore07"] = $ressource;
}

echo json_encode($result);
?>

With the RuneScape_API.class.php file found here http://pastebin.com/0Q2Qguux

Note: I am not even sure if those files do what I would like them to do. I am a begginer.

Upvotes: 1

Views: 93

Answers (1)

MarkSkayff
MarkSkayff

Reputation: 1374

get the url contents first and parse it accordingly.

For instance:

$url = "http://services.runescape.com/m=hiscore/index_lite.ws?player=DisplayName";
$f = file_get_contents($url);
$items = explode(' ', $f);

In $items you would have all the players xxx,xxx,xxx. This, of course, counts on spaces separating players in the file.

You can parse then each individual element in $items -probably with the same explode() function- to get the info you are looking for. Doing something like this for instance:

foreach($items as $item){
    $player = explode(",", $item);
    // $player[0] - will contain the first number
    // $player[1] - will contain second
    // $player[3] - will contain third
}

Upvotes: 2

Related Questions