2021-08-21 10:59:08 +00:00
|
|
|
<?php
|
|
|
|
// Vegan: https://world.openfoodfacts.org/api/v0/product/4251105509585.json
|
|
|
|
// Vegan uknown: https://world.openfoodfacts.org/api/v0/product/4008638170726.json
|
|
|
|
// Not vegan: 5000159404259
|
|
|
|
|
|
|
|
$barcode = $_GET['barcode'];
|
|
|
|
|
|
|
|
$data = file_get_contents('https://world.openfoodfacts.org/api/v0/product/'.$barcode.'.json');
|
|
|
|
|
2021-08-21 12:34:04 +00:00
|
|
|
$product = json_decode($data);
|
|
|
|
|
|
|
|
$array = $product->product->ingredients_analysis_tags;
|
|
|
|
$name = $product->product->product_name;
|
2021-08-21 10:59:08 +00:00
|
|
|
|
|
|
|
if (in_array("en:non-vegan", $array)) {
|
2021-08-21 12:34:04 +00:00
|
|
|
echo '"'.$name.'" is most likely not Vegan';
|
2021-08-21 10:59:08 +00:00
|
|
|
}
|
|
|
|
elseif (in_array("en:vegan-status-unknown", $array)) {
|
2021-08-21 12:34:04 +00:00
|
|
|
echo 'We are not sure if "'.$name.'" is vegan or not.';
|
2021-08-21 10:59:08 +00:00
|
|
|
}
|
|
|
|
elseif (in_array("en:vegan", $array)) {
|
2021-08-21 12:34:04 +00:00
|
|
|
echo '"'.$name.'" is Vegan!';
|
2021-08-21 10:59:08 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
echo "This product is not in our database yet.";
|
|
|
|
}
|
|
|
|
?>
|