PHP code example of samwilson / simple-wikidata
1. Go to this page and download the library: Download samwilson/simple-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/ */
samwilson / simple-wikidata example snippets
// The Sparql must return an ?item column.
$sparql = "SELECT ?item WHERE { ?item wdt:P31 wd:Q54050 } LIMIT 5";
$cache = new \Stash\Pool(new \Stash\Driver\FileSystem());
$people = new \Samwilson\SimpleWikidata\Query($sparql, 'en', $cache);
foreach ($people->getItems() as $person) {
// Each $person is an Item object.
$person->getLabel();
$person->getPropertyOfTypeItem();
$person->getPropertyOfTypeQuantity();
$person->getPropertyOfTypeIdentifier(); // External identifier
$person->getPropertyOfTypeUrl();
$person->getPropertyOfTypeTime();
$person->getPropertyOfTypeString(); // No language
$person->getPropertyOfTypeText(); // Has language
$person->getPropertyOfTypeCoord();
$person->getPropertyOfTypeFile(); // Commons media
}