0

I am making a search results page on my website, i am trying to make it detect when a company is searched and get a Wikipedia script from it.

But i only want it to show the code if the search is a company similar to google and bing

Google search for Microsoft showing information on companies.

i have the api setup to get the first paragraph. But now i need to detect if it is a business, get the images, and get the founders/ceos

here's the code i have so far

<div style='width:400px;float:right;border-radius:5px;border:1px solid black;margin:10px 20px;'>
  <?php
     $search = urlencode($search);
     $url = 'http://en.wikipedia.org/w/api.php?action=parse&page='.$search.'&format=json&prop=text&section=0';
     $ch = curl_init($url);
     curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt ($ch, CURLOPT_USERAGENT, "TestScript");
     $c = curl_exec($ch);
     $json = json_decode($c);
     $content = $json->{'parse'}->{'text'}->{'*'};
  ?>
  <div style='width:100px;height:100px;float:right;'>
     <?php
        //where i want the picture to display
     ?>
  </div>
  <div>
      <?php
          $pattern = '#<p>(.*)</p>#Us';
          if(preg_match($pattern, $content, $matches)){
              print clean(strip_tags($matches[1]));
          }
      ?>
  </div>
</div>

I've looked at the wikipedia API but i can't seem to find anything that shows if its in a section about companies or not, also crawling the page for images seems to be very laggy and unneeded. Also would using JavaScript be a better way of getting it then using php?

Zacharysr
  • 61
  • 3
  • 11
  • most companies at enwp uses the `Infobox company` infobox, so you could look for that, either by checking for that template using the API, or by looking in the wikitext for `{{Infobox company...` – leo Jan 19 '15 at 13:46
  • possible duplicate of [How do I get all articles about people from Wikipedia?](http://stackoverflow.com/questions/4017166/how-do-i-get-all-articles-about-people-from-wikipedia) – leo Jan 20 '15 at 14:43

1 Answers1

0

You'll have to do most of your own parsing, but the API can certain be used for this for you.