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
- What steps should be taken to ensure compliance with data usage permissions when extracting data from a website using PHP?
- What are the advantages of encoding the code for security reasons, even if the code is already well-written?
- What are the advantages of using $_POST instead of $_GET for passing data between PHP scripts?