Added product_name

This commit is contained in:
Philip 2021-08-21 14:34:04 +02:00
parent 1b6e659e05
commit e5daed063e

View file

@ -7,17 +7,19 @@ $barcode = $_GET['barcode'];
$data = file_get_contents('https://world.openfoodfacts.org/api/v0/product/'.$barcode.'.json');
$character = json_decode($data);
$array = $character->product->ingredients_analysis_tags;
$product = json_decode($data);
$array = $product->product->ingredients_analysis_tags;
$name = $product->product->product_name;
if (in_array("en:non-vegan", $array)) {
echo "Not Vegan";
echo '"'.$name.'" is most likely not Vegan';
}
elseif (in_array("en:vegan-status-unknown", $array)) {
echo "We're not sure.";
echo 'We are not sure if "'.$name.'" is vegan or not.';
}
elseif (in_array("en:vegan", $array)) {
echo "Vegan!";
echo '"'.$name.'" is Vegan!';
}
else {
echo "This product is not in our database yet.";