Advertisement
anasmansouri

Untitled

Nov 13th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.90 KB | None | 0 0
  1.  
  2. <?php
  3.  
  4. if (!isset($_GET["submit"])) {
  5.     echo "abrak 3la lbutton al 9lawi ";
  6. } else {
  7.     if (!isset($_GET["diet"]) || empty($_GET["diet"])) {
  8.         $diet = "";
  9.     } else {
  10.         $diet = $_GET["diet"];
  11.     }
  12.  
  13.     if (!isset($_GET["number"]) || empty($_GET["number"])) {
  14.         $number = "2";
  15.     } else {
  16.         $number = $_GET["number"];
  17.     }
  18.  
  19.     if (!isset($_GET["cuisine"]) || empty($_GET["cuisine"])) { // hadi ma5assehach tkoun haka hit  l utilisateur 5asse yn3teweh l7a9e ya5tar ktr mn cuisine wa7ed w5asse l sting li yd5al url ykouno mfar9ine fih le cuisine b ,+
  20.         $cuisine = "";
  21.     } else {
  22.         $cuisine = $_GET["cuisine"];
  23.     }
  24.  
  25.     if (!isset($_GET["maxReadyTime"]) || empty($_GET["maxReadyTime"])) {
  26.         $maxReadyTime = "120";
  27.     } else {
  28.         $maxReadyTime = $_GET["maxReadyTime"];
  29.     }
  30.  
  31.     $moukawinate = array();
  32.     for ($i = 0; $i < 4; $i++) {
  33.         array_push($moukawinate, $_GET["text" . $i]);
  34.     }
  35.     $result = implode(",", $moukawinate);
  36.     // echo $result;
  37.     // header("Content-Type: application/json");
  38.     // $apiKey = "c407ae4f6f7f4b56b46af81ea67caa2d";
  39.     $apiKey = "871c1b806d07427bbe2d79749900c182";
  40.     $url_Search_Recipes_by_IngredientsPure = "https://api.spoonacular.com/recipes/findByIngredients?apiKey=" . $apiKey . "&ingredients=" . $result . "&number=" . $number . "&ignorePantry=true";
  41.     $data = file_get_contents($url_Search_Recipes_by_IngredientsPure); // put the contents of the file into a variable
  42.     $characters = json_decode($data, false); // decode the JSON feed
  43.     //  echo $characters->results[1]->title;
  44.     //  header("location:" . $url_Search_Recipes_by_IngredientsPure);
  45.  
  46.     echo "" . $diet . "<br>";
  47.     $idrecipeAfterFiler = array();
  48.     $indiceRecipescharacters = array();
  49.     $prepa = "preparationMinutes";
  50.     $coking = "cookingMinutes";
  51.     $i = 0;
  52.     foreach ($characters as $recipe) {
  53.         //  echo "id :" . $recipe->id . "<br>";
  54.         $urlInformationOfRecipes = "https://api.spoonacular.com/recipes/" . $recipe->id . "/information?apiKey=" . $apiKey . "&includeNutrition=false";
  55.         $dataRecipeI = file_get_contents($urlInformationOfRecipes); // put the contents of the file into a variable
  56.         $ObjectRecipeI = json_decode($dataRecipeI, false);
  57.         if ($ObjectRecipeI->$diet) {
  58.             if ((int) ($ObjectRecipeI->readyInMinutes) <= $maxReadyTime) {
  59.                 array_push($idrecipeAfterFiler, $ObjectRecipeI->id);
  60.                 array_push($indiceRecipescharacters, $i);
  61.             }
  62.         }
  63.         $i++;
  64.     }
  65.  
  66.  
  67.  
  68.  
  69.     echo "test finished<br>";
  70.     foreach ($indiceRecipescharacters as $indice) {
  71.         echo "recipes name :" . $characters[$indice]->title;
  72.     }
  73.  
  74.  
  75.  
  76.  
  77.     // $urlTest = "https://api.spoonacular.com/recipes/" . $characters[0]->id . "/information?apiKey=" . $apiKey . "&includeNutrition=false";
  78.     //  header("location:" .  $urlTest);
  79. }
  80. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement