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 ...
Be my fan on Facebook and follow me on Twitter! Exclusive content for my Facebook fans and Twitter followers

This post has 10 comments

  1. Jerry

    on August 29, 2008 at 3:32 pm

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

  2. Emanuele Feronato

    on August 29, 2008 at 11:05 pm

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

  3. alec

    on August 29, 2008 at 11:54 pm

    What if we get a memory error?

  4. Emanuele Feronato

    on August 30, 2008 at 11:31 pm

    cheap server…

  5. 10 tips help you choosing the right hosting plan for your blog/arcade site : Emanuele Feronato

    on August 31, 2008 at 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 [...]

  6. Rarykos

    on September 1, 2008 at 6:21 pm

    Wow Emanuele, you know so many languages O_o

  7. Felix

    on October 18, 2008 at 10:59 pm

    nice for testing, thanks!

  8. Adrian

    on July 21, 2009 at 12:36 pm

    Another solution :)

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

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

    Controls:
    Tag:
    Game_id:

  9. Fernando

    on August 24, 2009 at 3:27 am

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

  10. Jocuri

    on March 23, 2011 at 1:08 pm

    Thanks! it’s good.