From a0e82c5862e1fe745da04d345fb6d4a6628ba9a9 Mon Sep 17 00:00:00 2001 From: Jan Willamowius Date: Wed, 3 Feb 2021 00:20:34 +0100 Subject: [PATCH] add more detailed barcodeSearch() --- EANSearch.php | 7 +++++++ README.md | 8 +++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/EANSearch.php b/EANSearch.php index 6b4f174..ea360ae 100644 --- a/EANSearch.php +++ b/EANSearch.php @@ -23,6 +23,13 @@ function barcodeLookup($ean, $lang = 1) { return $response->product->name; } + function barcodeSearch($ean, $lang = 1) { + $xml = file_get_contents("https://api.ean-search.org/api?" + . "op=barcode-lookup&token=$this->accessToken&ean=$ean&language=$lang"); + $response = new SimpleXMLElement($xml); + return $response->product; + } + function barcodePrefixSearch($prefix, $page = 0) { $xml = file_get_contents("https://api.ean-search.org/api?" . "op=barcode-prefix-search&token=$this->accessToken&prefix=$prefix&page=$page"); diff --git a/README.md b/README.md index 12361d7..9b1b387 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,8 @@ https://www.ean-search.org/ean-database-api.html ## Initialization ```php +include "EANSearch.php"; + // your access token from ean-search.org $accessToken = 'abcdef'; @@ -15,9 +17,13 @@ $eanSearch = new EANSearch($accessToken); ## Usage ```php $ean = '5099750442227'; -name = $eanSearch->barcodeLookup($ean); +$name = $eanSearch->barcodeLookup($ean); echo "$ean is $name\n"; +// more detailed response, preferably in English +$product = $eanSearch->barcodeSearch($ean, 1); +echo "$ean is $product->name from category $product->categoryName issued in $product->issuingCountry\n"; + $ok = $eanSearch->verifyChecksum($ean); echo "$ean is " . ($ok ? 'valid' : 'invalid') . "\n";