1

I want to know how to get data from infobox of Wikipedia in the right side, and how to put it in table in my website. I found this code that can get data and parse HTML, but I don't know how to put it in my own design.

$url = "http://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&format=json&titles=Niger&rvsection=0&rvparse";
$data = json_decode(file_get_contents($url), true);
$data = current($data['query']['pages']);
$regex = '#<\s*?table\b[^>]*>(.*)</table\b[^>]*>#s';
$code = preg_match($regex, $data["revisions"][0]['*'], $matches);
echo($matches[0]);
m4n0
  • 29,823
  • 27
  • 76
  • 89

1 Answers1

2

You can do it with a url call to the Wikipedia API like this:-

http://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&format=xmlfm&titles=Scary%20Monsters%20and%20Nice%20Sprites&rvsection=0

Replace the titles= section with your page title, and format=xmlfm to format=json if you want the article in json format.

  • 2
    i do that in my code , but how to parse this data of json with HTML tags?!! , I want a clear data to put it any way in my site. – Amr Elgohary Nov 16 '15 at 06:41