How can PHP be used to integrate existing search engines like Google into a website?

To integrate existing search engines like Google into a website using PHP, you can use Google Custom Search API. This API allows you to perform searches and display results on your website. You will need to obtain an API key and custom search engine ID from Google to use this service.

<?php
$apiKey = 'YOUR_API_KEY';
$searchEngineId = 'YOUR_SEARCH_ENGINE_ID';
$searchQuery = 'SEARCH_QUERY';

$url = 'https://www.googleapis.com/customsearch/v1?key=' . $apiKey . '&cx=' . $searchEngineId . '&q=' . urlencode($searchQuery);

$response = file_get_contents($url);
$results = json_decode($response);

foreach ($results->items as $item) {
    echo '<a href="' . $item->link . '">' . $item->title . '</a><br>';
    echo $item->snippet . '<br><br>';
}
?>