Skip to content

Instantly share code, notes, and snippets.

@mikkohei13
Created March 11, 2015 14:11
Show Gist options
  • Save mikkohei13/768825df0261f7577be8 to your computer and use it in GitHub Desktop.
Save mikkohei13/768825df0261f7577be8 to your computer and use it in GitHub Desktop.
<?php
// Getting species/taxon images from EOL
$species = $_GET['species'];
$species = str_replace(" ", "+", $species);
// Id
// Documentation: http://eol.org/api/docs/pages
$idUrl = "http://eol.org/api/search/1.0.json?q=" . $species . "&page=1&exact=false&filter_by_taxon_concept_id=&filter_by_hierarchy_entry_id=&filter_by_string=&cache_ttl=";
$idJson = file_get_contents($idUrl);
$idArr = json_decode($idJson, TRUE);
// presumes that the first name is correct
$id = $idArr['results'][0]['id'];
// Data
// Documentation: http://eol.org/api/docs/search
$dataUrl = "http://eol.org/api/pages/1.0/" . $id . ".json?images=4&videos=0&sounds=0&maps=0&text=0&iucn=false&subjects=overview&licenses=all&details=true&common_names=false&synonyms=false&references=false&vetted=0&cache_ttl=";
$dataJson = file_get_contents($dataUrl);
$dataArr = json_decode($dataJson, TRUE);
foreach ($dataArr['dataObjects'] as $nro => $data)
{
if ("image/jpeg" == $data['mimeType'])
{
echo "<a href='" . $data['eolMediaURL'] . "' />";
echo "<img src='" . $data['eolThumbnailURL'] . "' />";
echo "</a> ";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment