PHP code example of jamesfrost / wikidata

1. Go to this page and download the library: Download jamesfrost/wikidata library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jamesfrost / wikidata example snippets


$wikidata = new Wikidata;

$result = $wikidata->search('steve jobs');

if($result->isEmpty()) {
	echo 'no results';
	die();
}

$singleResult = $result->first();

$allResults = $result->get();

$entityId = $singleResult->getEntityId(); // Q26

$entities = $wikidata->entities('Q26');

$entities = $wikidata->entities('Q26', 'fr');

$entities = $wikidata->entities('Q26|Q106', 'en|fr|ch');

$entity = $entities->first();

$entity = $entities->get();

$entity = $entities->get('Q26');

$label = $entity->getLabel(); // Steve Jobs
$description = $entity->getDescription('de'); // US-amerikanischer Unternehmer, Mitbegründer von Apple Computer

$gender = $entity->getPropertyValues('P21'); // array(1) { [0]=> string(4) "male" }

$childs = $entity->getPropertyValues('P40', 'ru'); // array(1) { [0]=> string(35) "Бреннан-Джобс, Лиза" }