Wikidata provides a API for searching and retrieving data from wikidata.org.
composer require freearhey/wikidata$wikidata = new Wikidata;Search by entity title:
$result = $wikidata->search('steve jobs');Check if no search results
if($result->isEmpty()) {
echo 'no results';
die();
}Retrieve first entity in result list
$singleResult = $result->first();Retrieve all results
$allResults = $result->get();Get entity id
$entityId = $singleResult->getEntityId(); // Q26Get single entity by id:
$entities = $wikidata->entities('Q26');Get single entity with preset language (default: en)
$entities = $wikidata->entities('Q26', 'fr');Get few entities by id and more languages
$entities = $wikidata->entities('Q26|Q106', 'en|fr|ch');Retrieve first entity
$entity = $entities->first();Get all entities
$entity = $entities->get();Get single entity by id
$entity = $entities->get('Q26');Get entity label and description (default language: en)
$label = $entity->getLabel(); // Steve Jobs
$description = $entity->getDescription('de'); // US-amerikanischer Unternehmer, Mitbegründer von Apple ComputerGet entity property values by property id (e.g. P21) if it exists. All list properties you can find here
$gender = $entity->getPropertyValues('P21'); // array(1) { [0]=> string(4) "male" }And with language property (default: en)
$childs = $entity->getPropertyValues('P40', 'ru'); // array(1) { [0]=> string(35) "Бреннан-Джобс, Лиза" }That's all.
Wikidata is licensed under the MIT license