Skip to content

Commit

Permalink
add more detailed barcodeSearch()
Browse files Browse the repository at this point in the history
  • Loading branch information
willamowius committed Feb 2, 2021
1 parent 0ac9c8f commit a0e82c5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 7 additions & 0 deletions EANSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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";

Expand Down

0 comments on commit a0e82c5

Please sign in to comment.