Advertisement
Guest User

PHP Code

a guest
Nov 26th, 2012
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.36 KB | None | 0 0
  1. #!/usr/local/bin/php
  2.  
  3. <?php
  4.  
  5.         $movieName = $_POST["movieName"];
  6.         //echo "Movie Name: [$movieName] <br/>";
  7.         $movieName = preg_replace('/[^a-zA-Z0-9-_() .]/','',$movieName);
  8.         //echo "Searching for: [$movieName] <br/><br/>";
  9.  
  10.         $neg = 0;
  11.         $pos = 0;
  12.         $ntl = 0;
  13.         $tot = 0;
  14.  
  15.         // open file and fill up the neg, pos and ntl values from it
  16.         $handle = fopen("<a http file", "r"); // this works!
  17.         if ($handle) {
  18.                 while ($buffer = fgets($handle, 1024)) {
  19.                         // filter output based on the movie name
  20.                         if (strpos($buffer, $movieName) !== false) {
  21.                                 //echo "[$buffer]";
  22.                                 //echo "<br/>";
  23.  
  24.                                 preg_match_all('!\d+!', $buffer, $matches);
  25.                                 $results = count($matches[0]);
  26.                                 $num = $matches[0][$results-1];
  27.  
  28.                                 if (strpos($buffer, "negative") !== false) {
  29.                                         $neg = $num;
  30.                                 } else if (strpos($buffer, "neutral") !== false) {
  31.                                         $ntl = $num;
  32.                                 } else {
  33.                                         $pos = $num;
  34.                                 }
  35.                         } else {
  36.                                 //echo "Ignoring [$buffer] <br/>";
  37.                         }
  38.                 }
  39.                 fclose($handle);
  40.         } else {
  41.                 echo "Unable to open output file from S3. Make sure the file is public!";
  42.                 die();
  43.         }
  44.  
  45.         $tot = $neg + $pos + $ntl;//echo "Pos: $pos, Neg: $neg, Ntl: $ntl, Total: $tot";
  46.  
  47.         $rating = ((($ntl*5)+($pos*10))/$tot);
  48.         //echo "<br/>Rating: $rating";
  49.  
  50.         //echo "<br/>";
  51.  
  52.         /////////////////// IMDB /////////////////////
  53.         $movieName = preg_replace('/[ ]/','+',$movieName);
  54.         $uri = "http://worldweatheronline.com/feed/weather.ashx?q=schruns,austria&format=json&num_of_days=5&key=8f2d1ea151085304102710";
  55.         //echo "URI: [$uri] <br/>";
  56.  
  57.         header('Content-Type: application/json');
  58.         $file = file_get_contents($uri);
  59.         $error = error_get_last();
  60.         echo $error['message'];
  61.         echo $file;
  62.  
  63. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement