Jump to content

Recommended Posts

Hi I have the following code which grabs a table from a website

[code]<?php

$user = 'devil may6';

function RSstats($url)
{
$rssstring = file_get_contents($url);
preg_match_all('#<table cellpadding="3" cellspacing="0" border=0>(.*?)</table>#s', $rssstring, $stat);

$score = $stat[1][0];
$score = strip_tags($score);
echo $score;

}

RSstats('http://hiscore.runescape.com/lang/en/aff/runescape/hiscorepersonal.ws?user1=' . $user);

?>


[/code]

and displays it like this

[quote]Personal scores for Devil May6 Skill RankLevelXP Overall 999,998 667 1,597,232 Attack Not Ranked Defence 529,783 57 214,857 Strength Not Ranked Hitpoints 932,293 55 172,561 Ranged Not Ranked Prayer 325,757 46 68,243 Magic 281,017 62 349,834 Cooking Not Ranked Woodcutting 432,602 65 465,040 Fletching 565,357 38 30,988 Fishing Not Ranked Firemaking Not Ranked Crafting Not Ranked Smithing Not Ranked Mining Not Ranked Herblore 219,323 34 21,909 Agility Not Ranked Thieving Not Ranked Slayer Not Ranked Farming Not Ranked Runecraft Not Ranked Construction Not Ranked[/quote]

I would like this information put into an array like this:

[quote]Array
(
    [0] => Array
        (
            [0] => Overall
            [1] => 999,998
            [2] => 667
            [3] => 1,597,232
        )

    [1] => Array
        (
            [0] => Attack
            [1] => Not Ranked
        )

    [2] => Array
        (
            [0] => Defence
            [1] => 529,783
            [2] => 57
            [3] => 214,857
        )
etc...[/quote]

But I dont know how i would go about this could anyone help please?
Link to comment
https://forums.phpfreaks.com/topic/15385-arrays/
Share on other sites

Try this

[code]<?php

$txt = "Personal scores for Devil May6 Skill RankLevelXP Overall 999,998 667 1,597,232 Attack Not Ranked Defence 529,783 57 214,857 Strength Not Ranked Hitpoints 932,293 55 172,561 Ranged Not Ranked Prayer 325,757 46 68,243 Magic 281,017 62 349,834 Cooking Not Ranked Woodcutting 432,602 65 465,040 Fletching 565,357 38 30,988 Fishing Not Ranked Firemaking Not Ranked Crafting Not Ranked Smithing Not Ranked Mining Not Ranked Herblore 219,323 34 21,909 Agility Not Ranked Thieving Not Ranked Slayer Not Ranked Farming Not Ranked Runecraft Not Ranked Construction Not Ranked";

$cats = array('Overall', 'Attack', 'Defence', 'Strength', 'Hitpoints',
'Ranged', 'Prayer', 'Magic', 'Cooking', 'Woodcutting', 
'Fletching', 'Fishing', 'Firemaking', 'Crafting', 'Smithing',
'Mining', 'Herblore', 'Agility', 'Thieving', 'Slayer',
'Farming', 'Runecraft', 'Construction');
$score = array();
$data = explode (' ', $txt);
$key = 'header';
foreach ($data as $word) {
    if (in_array($word, $cats)) {
    $score[$word] = array();
    $key = $word;
    }
    elseif ($word=='Not') {
    $score[$key][] = 'Not ranked';
    }
    elseif ($word=='Ranked') {
    continue;
    }
    else $score[$key][] = $word;
}

// view the results

echo '<pre>', print_r($score, true), '</pre>';
?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/15385-arrays/#findComment-62489
Share on other sites

Yes that is how i wanted the data splitting up but the problem there is you have manually defined the txt to be put into an array, that txt will change and thats y i need to get it using file(). is there a way to do that after getting the data from the website rather than manually defining $txt? i tried changing $txt so to $txt = $score; but that messed it up.
Link to comment
https://forums.phpfreaks.com/topic/15385-arrays/#findComment-62494
Share on other sites

try this

[code]
$user = 'devil may6';

function RSstats($url)
{
$rssstring = file_get_contents($url);
preg_match_all('#<table cellpadding="3" cellspacing="0" border=0>(.*?)</table>#s', $rssstring, $stat);

$score = $stat[1][0];
$score = strip_tags($score);
return $score;

}

$txt = RSstats('http://hiscore.runescape.com/lang/en/aff/runescape/hiscorepersonal.ws?user1=' . $user);
[/code]
Link to comment
https://forums.phpfreaks.com/topic/15385-arrays/#findComment-62511
Share on other sites

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.