Guest

Houlala

By: a guest on Aug 18th, 2008  |  syntax: PHP  |  size: 1.54 KB  |  hits: 485  |  expires: Never
download  |  raw  |  embed  |  report abuse
Copied
  1. <?php
  2.        
  3.         function get_content($url)
  4.         {
  5.                 $ch = curl_init();
  6.                
  7.                 curl_setopt($ch, CURLOPT_URL, $url);
  8.                
  9.                 ob_start();
  10.                
  11.                 curl_exec($ch);
  12.                 curl_close($ch);
  13.                 $string = ob_get_contents();
  14.                
  15.                 ob_end_clean();
  16.                
  17.                 $string = html_entity_decode($string);
  18.                 $string = html_entity_decode($string);
  19.                
  20.                 return $string;
  21.         }
  22.        
  23.         $api     = "api.viedemerde.fr";
  24.         $key     = "readonly";
  25.         $page    = "view/random";
  26.         $version = get_content("http://$api/version");
  27.         $content = utf8_decode(get_content("http://$api/$version/$page?key=$key"));
  28.        
  29.         preg_match('/<vdm id=\"(.*)\">/', $content, $matches);
  30.         $id = $matches[1];
  31.        
  32.         preg_match('/<auteur>(.*)<\/auteur>/', $content, $matches);
  33.         $auteur = $matches[1];
  34.        
  35.         preg_match('/<categorie>(.*)<\/categorie>/', $content, $matches);
  36.         $categorie = $matches[1];
  37.        
  38.         preg_match('/<texte>(.*)<\/texte>/', $content, $matches);
  39.         $texte = $matches[1];
  40.        
  41.         preg_match('/<date>(.*)<\/date>/', $content, $matches);
  42.         $date = date("\l\e d/m/y à H:i", strtotime($matches[1]));
  43.        
  44. ?>
  45.  
  46.  
  47. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  48. <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
  49.         <head>
  50.                 <title><?php echo $auteur; ?> a une vie de merde...</title>
  51.                 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
  52.         </head>
  53.         <body>
  54.                 <hr />
  55.                 <div>
  56.                         <?php echo "$auteur a une vie de merde ($categorie - $date) [$id]"; ?>
  57.                 </div>
  58.                 <hr />
  59.                 <div>
  60.                         <?php echo $texte; ?>.
  61.                 </div>
  62.                 <hr />
  63.         </body>
  64. </html>