Jump to content

Converting Feed Into Readable List


jacko_162

Recommended Posts

I have the following link;

 

http://eve-kill.net/epic/involvedCorp:Skulldogs/mask:64/mailLimit:5

 

which pulls an array of victimCorpName and limits the results to 5. how can i get it to list these in a bullet point list and only show the VictimCorpName for example:

  • victimCorpName
  • victimCorpName
  • victimCorpName
  • victimCorpName
  • victimCorpName

and if i remove the "limit" is it possible to count the amount of times a certain "victimCorpName" comes up, for example:

 

FSB-Alpha: x7

 

i tried to use the print_r(&myArray) but to no avail.

 

any help would be appreciated.

 

this is my current code theory:

 

<?php
$file_contents = file_get_contents('http://eve-kill.net/epic/involvedCorp:Skulldogs/mask:64/mailLimit:5');
$decode = json_decode($file_contents, true);
$encode = json_encode($file_contents);
//echo $data[2]->victimCorpName;
//echo $data->title;
print_r($decode);

?>

Link to comment
Share on other sites

try

<?php
$file_contents = file_get_contents('http://eve-kill.net/epic/involvedCorp:Skulldogs/mask:64/mailLimit:5');
$decode = json_decode($file_contents, true);
$arr = array();
foreach ($decode as $d) {
   $arr[] = $d['victimCorpName'];
}
$counts = array_count_values($arr);
echo '<pre>'.print_r($counts, 1).'</pre>';
?>

RESULTS

Array
(
   [FSB-ALFA] => 3
   [Ministry of War] => 1
   [solar Wind] => 1
)

Link to comment
Share on other sites

works great. Thank you,

 

ok and perhaps my last question, the foreach() works and i got my list.

 

on your count code, how can i get it to add up all the amounts? and give a total?

 

for example:

 

Array

(

[FSB-ALFA] => 3

[Ministry of War] => 1

[solar Wind] => 1

)

Total: 5

Link to comment
Share on other sites

i looked at array_sum but i cant seem to get it to add correctly:

 

<?php
$file_contents = file_get_contents('http://eve-kill.net/epic/involvedCorp:Skulldogs/mask:16/mailLimit:10');
$decode = json_decode($file_contents, true);
$arr = array();
foreach ($decode as $d) {
    $arr[] = $d['victimName'];
}
$counts = array_count_values($arr);
$sum = array_sum($decode);
echo '<pre>'.print_r($counts, 1).'</pre>';
echo "<br><br><br>SUM: ";
echo "" . $sum . "\n";
?>

 

it outputs:

Array
(
   [R4K-8L] => 1
   [Calette Zardina] => 1
   [sylouis] => 1
   [sylia Nimlas] => 1
   [Tcpp24] => 2
   [Greg Focker Gaylord] => 2
   [PMV-G6 VII - Moon 4] => 2
)


SUM: 0

 

it should give me SUM: 10

Link to comment
Share on other sites

Yes, that's the on to sum. You have something like this by now

 

<?php

$file_contents = file_get_contents('http://eve-kill.net/epic/involvedCorp:Skulldogs/mask:64/mailLimit:10');
$decode = json_decode($file_contents, true);
$arr = array();
foreach ($decode as $d) {
    $arr[] = $d['victimCorpName'];
}
$counts = array_count_values($arr);

/*************************
* bullet list
**************************/
echo "<ul>\n";
foreach ($counts as $name=>$n) {
   echo "<li>$name ($n)</li>\n";
}
echo "</ul>\n";
/******
* Total
*******/
echo "<br />Total : " . array_sum($counts);
?>

Link to comment
Share on other sites

BTW, the total should always be the same value as your mailLimit attribute in the URL

 

yeah i was checking that against the result, hence why i noticed it was wrong. and thank you for the formatting above. looks better..!

 

say if i pull a result of $sum as 1000000 (how can i output this as "1 Million", or 1350000 as "1.35 Million, or 350000 as "0.35 Million" etc..)

 

i looked at number_format() but to no avail.

Link to comment
Share on other sites

After a quick google search i found the following function:

 

function Humanize($size) {
$size = preg_replace('/[^0-9]/','',$size);
$sizes = array("", "K", "M", "B");
if ($size == 0) { return('n/a'); } else {
return (round($size/pow(1000, ($i = floor(log($size, 1000)))), 0) . $sizes[$i]); }
}

echo "<br><br>Total:" . Humanize($result);

 

it now outputs the short form, but doesnt include decimal places (for example it shows 33,175,961,290 as 33B, whereas i want it to show as 33.1B)

 

any clues to alter?

Link to comment
Share on other sites

After a quick google search i found the following function:

 

function Humanize($size) {
$size = preg_replace('/[^0-9]/','',$size);
$sizes = array("", "K", "M", "B");
if ($size == 0) { return('n/a'); } else {
return (round($size/pow(1000, ($i = floor(log($size, 1000)))), 0) . $sizes[$i]); }
}

echo "<br><br>Total:" . Humanize($result);

 

it now outputs the short form, but doesnt include decimal places (for example it shows 33,175,961,290 as 33B, whereas i want it to show as 33.1B)

 

any clues to alter?

 

actually thinking about it it should work as is.

 

thanks for help guys..

Link to comment
Share on other sites

If you need decimal places, alter the hightlight parameter to the number required:

 

return (round($size/pow(1000, ($i = floor(log($size, 1000)))), 3) . $sizes[$i]);

 

aaah many thanks,

 

another quick one if you can?

 

say i pull a feed like above in my original posts, and have a limit of 25, then count them and have a list like so:

 

echo '<pre>'.print_r($counts, 1).'</pre>';

 

Outputs:

 [FSB-ALFA] => 9
 [Ministry of War] => 7
 [solar Wind] => 5
 [FSB-ALFA] => 3
 [Ministry of War] => 1
 [solar Wind] => 1

 

is it possible to only echo the top 1 (with most counts) instead of the whole array:

 

[FSB-ALFA] => 9

Edited by jacko_162
Link to comment
Share on other sites

using this code by the way:

 

<?php
$file_contents = file_get_contents('http://eve-kill.net/epic/involvedCorp:Skulldogs/mask:64/mailLimit:10');
$decode = json_decode($file_contents, true);
$arr = array();
foreach ($decode as $d) {
		    $arr[] = $d['victimCorpName'];
}
$counts = array_count_values($arr);
/*************************
* bullet list
**************************/
echo "<ul>\n";
foreach ($counts as $name=>$n) {
    echo "<li>$name ($n)</li>\n";
}
echo "</ul>\n";
/******
* Total
*******/
echo "<br />Total : " . array_sum($counts);
?>

 

which outputs nicely formatted:

 

   Fleet of the Eternal Night (3)
   A0 Inc (1)
   The Curse of Distant Stars (2)
   Lamb Federation Navy (1)
   Deep Space Supplies (1)
   LdW Industries (1)
   Silent Sentinels (1)

Total : 10

 

looking at the above it doesnt sort them in DESC order... so i would need it in decending order and to limit it to the top 1 or 2

Link to comment
Share on other sites

I added a couple of lines - with comments

 

<?php

$file_contents = file_get_contents('http://eve-kill.net/epic/involvedCorp:Skulldogs/mask:64/mailLimit:10');
$decode = json_decode($file_contents, true);
$arr = array();
foreach ($decode as $d) {
    $arr[] = $d['victimCorpName'];
}
$counts = array_count_values($arr);

arsort($counts);				 // sort in DESC order

$topcounts = array_slice ($counts, 0, 2, true);	   // the "2" dictates how many to show

/*************************
* bullet list
**************************/
echo "<ul>\n";
foreach ($topcounts as $name=>$n) {
   echo "<li>$name ($n)</li>\n";
}
echo "</ul>\n";
/******
* Total
*******/
echo "<br />Total : " . array_sum($counts);

?>

Link to comment
Share on other sites

hmmm im getting the following error;

 

Warning: array_count_values() [function.array-count-values]: Can only count STRING and INTEGER values! in /homepages/*****/feed/topKillers.php on line 10

 

using the below code:

 

<?php

$file_contents = file_get_contents('http://eve-kill.net/epic/involvedCorp:Skulldogs/mask:524288/mailLimit:1');

$decode = json_decode($file_contents, true);
$arr = array();
foreach ($decode as $d) {
 $arr[] = $d['characterName'];
}
$counts = array_count_values($arr); //error occurs here
echo '<pre>'.print_r($counts, 1).'</pre>';
?>

 

is there a work around to be able to list and count the "characterName" without the errors?

Edited by jacko_162
Link to comment
Share on other sites

The returned array structure is completely diferrent from that returned with your previous mask value. You need to adjust your code accordingly.

 

Although this may need changing if limit increased.

 

<?php

$file_contents = file_get_contents('http://eve-kill.net/epic/involvedCorp:Skulldogs/mask:524288/mailLimit:1');

$decode = json_decode($file_contents, true);
echo '<pre>'.print_r($decode, 1).'</pre>';				    // view new structure
$arr = array();
foreach ($decode[0]['involved'] as $d) {			 //process  new structure
	 $arr[] = $d['characterName'];
}
$counts = array_count_values($arr); //error occurs here
echo '<pre>'.print_r($counts, 1).'</pre>';
?>

Edited by Barand
Link to comment
Share on other sites

The returned array structure is completely diferrent from that returned with your previous mask value. You need to adjust your code accordingly.

 

Although this may need changing if limit increased.

 

<?php

$file_contents = file_get_contents('http://eve-kill.net/epic/involvedCorp:Skulldogs/mask:524288/mailLimit:1');

$decode = json_decode($file_contents, true);
echo '<pre>'.print_r($decode, 1).'</pre>';				 // view new structure
$arr = array();
foreach ($decode[0]['involved'] as $d) {			 //process new structure
	 $arr[] = $d['characterName'];
}
$counts = array_count_values($arr); //error occurs here
echo '<pre>'.print_r($counts, 1).'</pre>';
?>

 

using the above structure, it only echos and counts from the array [0] if that makes sense, i will change the "mailLimit" to 500 eventually and i need to to show the top 10 chacterNames and the amount of times that character appears like so:

 

   [scalira] => 10
   [Rip1ey] => 9
   [scalira] => 8
   [Rip1ey] => 7
   [scalira] => 6
   [Rip1ey] => 5
   [scalira] => 4
   [Rip1ey] => 3
   [Rip1ey] => 2
   [Rip1ey] => 1

Link to comment
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.