Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE HTML>
- <HTML>
- <head>
- <title>ingredients</title>
- </head>
- <body>
- <form>
- </form>
- <!-----------------------------------inputs--------------------------------->
- <form name="myform" method='get'>
- <input name="search" type="text" placeholder="what in your fridge "><br>
- <input name="time" type="number" placeholder="type number of minutes ">
- <!-----------------------------------list des choix--------------------------------->
- <p>enter option : </p>
- <select name='option'>
- <option value="none">none</option>
- <option value="vegetarian">vegetarian</option>
- <option value="vegan">vegan</option>
- <option value="cheap">cheap</option>
- <option value="veryHealthy">very healthy</option>
- <option value="dairyFree">dairy free</option>
- <option value="whole30">whole 30</option>
- </select>
- <button type="submit" name="button" value="submit">Search</button>
- </p>
- <p>
- <!-----------------------------------php--------------------------------->
- <?php
- if (isset($_GET['button'])) //------------------->si le bouton est cliquee
- {
- //------------------->test sur les separateur de notre ingredients
- $str = str_replace(',', ',+', $_GET['search']);
- $str = str_replace('-', ',+', $str);
- $str = str_replace(';', ',+', $str);
- $str = str_replace('/', ',+', $str);
- $str = str_replace(' ', ',+', $str);
- $str = str_replace(' ', ',+', $str);
- $str = str_replace(',+,+', ',+', $str);
- $str = str_replace(',+,+,+', ',+', $str);
- //------------------->pswd de notre api
- $apiKey = "8ce7c20403914b92900a12bff524a951";
- //------------------->variables
- $stockIndex = array(); //------------------->tableaux des index de notre plat filtrees
- $stockID = array(); // ---------------------->tableaux des Id des recipes preferer
- $number = 2; //nombre max des recettes a afficher
- $filterOfUser = "" . $_GET["option"]; //-------------------> string de notre choix de la list select soit vegan,vegetarian...
- $maxTime = (int) $_GET["time"]; //-------------------> le temps en minutes
- $stockRecipe = array();
- //------------------->un objet de notre plat a partir des ingredients
- $url1 = "https://api.spoonacular.com/recipes/findByIngredients?apiKey=" . $apiKey . "&ingredients=" . $str . "&number=" . $number;
- $data1 = file_get_contents($url1);
- $characters1 = json_decode($data1, false);
- //------------------->attribution des id des recettes qui satisfait notre choix dans le tableau $stockId
- for ($i = 0; $i < 2; $i++) {
- //-------------------> un objet qui contient notre plat en bouclant sur character1->id
- $url2 = "https://api.spoonacular.com/recipes/" . $characters1[$i]->id . "/information?apiKey=" . $apiKey . "&includeNutrition=false";
- $data2 = file_get_contents($url2);
- $characters2 = json_decode($data2, false);
- //-------------------> test sur list et nbr de minutes
- if ((($filterOfUser == 'none') || ($characters2->$filterOfUser)) && (($characters2->readyInMinutes <= $maxTime) || (empty($maxTime)))) {
- array_push($stockIndex, $i);
- array_push($stockID, $characters2->id);
- array_push($stockRecipe, $characters2->instructions);
- }
- }
- //------------------->pour chaque id on affiche
- foreach ($stockIndex as $i) {
- //------------------->titre et image de notre plat
- echo "<h1>" . $characters1[$i]->title . "</h1><br><img src=" . $characters1[$i]->image . " width='400' /><br>";
- //-------------------> les ingredient utiliser de votre choix
- echo '<h4>ingredients :</h4> ';
- $url3 = "https://api.spoonacular.com/recipes/" . $stockID[$i] . "/ingredientWidget.json?apiKey=" . $apiKey;
- $data3 = file_get_contents($url3);
- $ObjetIngredient = json_decode($data3, false);
- // 9lab 3la les ingredients
- foreach ($ObjetIngredient->ingredients as $ingredient) {
- echo ' <br><img src="https://spoonacular.com/cdn/ingredients_100x100/' . $ingredient->image . '" width="30" /><br>' . $ingredient->name . '<br>quantity : ' . $ingredient->amount->metric->value . ' ' . $ingredient->amount->metric->unit;
- }
- echo '<h4>recipe : </h4>';
- echo '<section style="background-color:pink ; border:3px solid red ; padding:15px ; margin:5px">';
- echo $stockRecipe[$i];
- echo '</section>';
- }
- }
- ?>
- </p>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement