Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * renvoie un array du style
- * "hordes" => 582
- * "odyssey" => 200
- * "fever" => 40
- * et ce qui valent 0 ne sont pas dans l'array.
- */
- function getScores($uid) {
- $html = file_get_contents("http://www.twinoid.com/fr/user/".$uid);
- $out = array();
- if(preg_match_all('#<div class="tid_score">([0-9]+)</div>#', $html, $scores)) {
- $n = count($scores[1]);
- preg_match_all('#<div class="tid_name">(.*)</div>#', $html, $jeux);
- for($i = 0; $i < $n; $i++) {
- $out[$jeux[1][$i]] = $scores[1][$i];
- }
- }
- return $out;
- }
- //petite fonction pour faire le total, pour le petit exemple qui suit :) (tu devrais comprendre facilement)
- function somme($a) {
- $somme = 0;
- foreach($a as $val)
- $somme += $val;
- return $somme;
- }
- function moyenne($a) {
- $moyenne = 0;
- if(count($a) > 0) {
- foreach($a as $val)
- $moyenne += $val;
- $moyenne /= count($a);
- }
- return $moyenne;
- }
- //un petit exemple de code pour afficher dans un tableau les données
- echo "<table>";
- echo "<tr><td><strong>Nom du jeu</strong></td><td><strong>Score du joueur</strong></td></tr>";
- $scores = getScores($_GET["uid"]);
- foreach($scores as $jeu => $score) {
- echo "<tr><td><span style='font-weight:bold;'>".$jeu."</span></td><td>".$score."</td></tr>";
- }
- echo "<tr><td><strong>Somme</strong></td><td>".somme($scores)."</td></tr>";
- echo "<tr><td><strong>Moyenne</strong></td><td>".moyenne($scores)."</td></tr>";
- echo "</table>";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment