title: Extract data from Wikidata using PHP
body: <p>I have used Faker to generate persons and I want to do the same thing using Wikidata. By getting names, date of birth, gender, first paragraph and other specified similar data. In addition being able to avoid duplicates by checking existing persons (e.g Q4926) I have fetched before. Wikidata Query = <a href="https://w.wiki/5LUr" rel="nofollow noreferrer">https://w.wiki/5LUr</a></p>
  <p>Is it possible to use <a href="https://github.com/freearhey/wikidata" rel="nofollow noreferrer">freearhey/wikidata</a> or <a href="https://github.com/addwiki/wikibase-api" rel="nofollow noreferrer">addwiki/wikibase-api</a> or should <a href="https://query.wikidata.org/sparql" rel="nofollow noreferrer">query.wikidata.org/sparql</a> be used diretly</p>
  <p>Code snippet currently used</p>
  <pre><code>if ($s == 'generate_fake_users') {
      require &quot;assets/libraries/fake-users/vendor/autoload.php&quot;;
      $faker = Faker\Factory::create();
      if (empty($_POST['password'])) {
          $_POST['password'] = '123456789';
      }
      $count_users = $_POST['count_users'];
      $password = $_POST['password'];
      $avatar = $_POST['avatar'];
      ob_end_clean();
          header(&quot;Content-Encoding: none&quot;);
          header(&quot;Connection: close&quot;);
          ignore_user_abort();
          ob_start();
          header('Content-Type: application/json');
          echo json_encode(array(
              'status' =&gt; 200
          ));
          $size = ob_get_length();
          header(&quot;Content-Length: $size&quot;);
          ob_end_flush();
          flush();
          session_write_close();
          if (is_callable('fastcgi_finish_request')) {
              fastcgi_finish_request();
          }
      for ($i=0; $i &lt; $count_users; $i++) { 
          $genders = array_keys($wo['genders']);
          $random_keys = array_rand($genders, 1);
          $gender = array_rand(array(&quot;male&quot;, &quot;female&quot;), 1);
          $gender = $genders[$random_keys];
          $re_data  = array(
              'email' =&gt; Site_Secure(str_replace(&quot;.&quot;, &quot;_&quot;, $faker-&gt;userName) . '_' . rand(111, 999) . &quot;@domain.com&quot;, 0),
              'username' =&gt; Site_Secure($faker-&gt;userName . '_' . rand(111, 999), 0),
              'password' =&gt; Site_Secure($password, 0),
              'email_code' =&gt; Site_Secure(md5($faker-&gt;userName . '_' . rand(111, 999)), 0),
              'src' =&gt; 'Fake',
              'gender' =&gt; Site_Secure($gender),
              'lastseen' =&gt; time(),
              'active' =&gt; 1,
              'first_name' =&gt; $faker-&gt;firstName($gender),
              'last_name' =&gt; $faker-&gt;lastName
          );
          if ($avatar == 1) {
              $urls = array(&quot;http://lorempixel.com/&quot;.$wo['profile_picture_width_crop'].&quot;/&quot;.$wo['profile_picture_height_crop'].&quot;/people&quot;,&quot;https://placeimg.com/&quot;.$wo['profile_picture_width_crop'].&quot;/&quot;.$wo['profile_picture_height_crop'].&quot;/people&quot;);
              $rand = rand(0,1);
              $url = $urls[$rand];
              $a = Site_ImportImageFromFile($url,'_url_image','avatar');
              if (!empty($a)) {
                  $re_data['avatar'] = $a;
              }
          }
          $add_user = Site_RegisterUser($re_data);
      }
      header(&quot;Content-type: application/json&quot;);
      echo json_encode($data);
      exit();
  }
  </code></pre>