What are some common methods for automatically displaying Wikipedia articles on a website using PHP?
One common method for automatically displaying Wikipedia articles on a website using PHP is by using the Wikipedia API. By making a request to the API, you can retrieve the content of a specific Wikipedia page and display it on your website. Another method is to use a PHP library like Mediawiki API, which provides a more user-friendly interface for interacting with Wikipedia content.
<?php
$articleTitle = "PHP"; // Specify the title of the Wikipedia article you want to display
$url = "https://en.wikipedia.org/w/api.php?action=query&format=json&prop=extracts&exintro=&explaintext=&titles=" . urlencode($articleTitle);
$response = file_get_contents($url);
$data = json_decode($response, true);
$pages = $data['query']['pages'];
foreach ($pages as $page) {
echo $page['extract']; // Display the extracted content of the Wikipedia article
}
?>
Keywords
Related Questions
- Are there any best practices or security considerations to keep in mind when implementing dynamic content generation with PHP and databases?
- How can the layout of a website be independent of screen resolution and dependent on viewport size?
- What best practices should be followed when using regex for text manipulation in PHP?