Parsing MochiAds feed in a friendly way

I made this little script to debug my portal script (almost completed) and I want to share it with you.

It simply shows MochiAds feed in a friendly way, using lists.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
 
$mochi_url = "http://www.mochiads.com/feeds/games?format=json"; 
$feed = file_get_contents($mochi_url); 
$games_array = json_decode($feed, true);
 
$number_of_games = count($games_array[games]);
 
echo "<ol>";
for($x=0;$x<$number_of_games;$x++){
     echo "<li><ul>";     
     foreach($games_array[games][$x] as $varname => $varvalue) {
          echo "<li><strong>$varname</strong>: ";
          if(is_array($varvalue)){
               echo "<ol>";
               foreach($varvalue as $subvar => $subvalue){
                    echo "<li>";
                    if(is_array($subvalue)){
                         foreach($subvalue as $lastvar => $lastvalue){
                              echo "$lastvalue";
                              if(!$lastvar){
                                   echo ": ";
                              }
                         }
                    }
                    else{
                         echo "$subvalue";
                    }
                    echo "</li>";
               }
               echo "</ol>";
          }
          else{
               if(strpos($varvalue,"http")!==false){
                    echo "<a href = \"$varvalue\" target = \"_blank\">$varvalue</a>";
               }
               else{
                    echo $varvalue;
               }
          }
          echo "</li>";
     }
     echo "</ul></li>";
}
echo "</ol>";
 
?>

Hope you will find it useful.

Rate this post: 1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 3.50 out of 5)
Loading ... Loading ...
If you found this post useful, please consider a small donation.

9 Responses to “Parsing MochiAds feed in a friendly way”

  1. Jerry on August 29th, 2008 3:32 pm

    When I run the page I get a undifined function call at line 5.

  2. Emanuele Feronato on August 29th, 2008 11:05 pm

    That’s because your hosting server does not support Php 5.2

  3. alec on August 29th, 2008 11:54 pm

    What if we get a memory error?

  4. Emanuele Feronato on August 30th, 2008 11:31 pm

    cheap server…

  5. Rarykos on September 1st, 2008 6:21 pm

    Wow Emanuele, you know so many languages O_o

  6. Felix on October 18th, 2008 10:59 pm

    nice for testing, thanks!

  7. Adrian on July 21st, 2009 12:36 pm

    Another solution :)

    <img src="” alt=”"/>

    <a href="page_detail.php?game_name=”>

    Controls:
    Tag:
    Game_id:

  8. Fernando on August 24th, 2009 3:27 am

    I was just starting to work on something like this….It looks good.

Leave a Reply




Trackbacks

  1. 10 tips help you choosing the right hosting plan for your blog/arcade site : Emanuele Feronato on August 31st, 2008 10:20 pm

    [...] hosting plan can handle enough work, you should at least be able to run the script published in Parsing MochiAds feed in a friendly way or you won’t be able to have your WordPress arcade [...]

flash games company