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.

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

Hope you will find it useful.

Improve the blog rating this post
Tell me what do you think about this post. I'll write better and better entries.
1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 3.5 out of 5)
Loading ... Loading ...

7 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!

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 [...]