How can a PHP script be optimized to display the like count from Facebook in a simple and efficient manner on a webpage?

To optimize a PHP script to display the like count from Facebook in a simple and efficient manner on a webpage, you can use the Facebook Graph API to fetch the like count for a specific URL. This can be done by making a GET request to the Graph API endpoint with the URL of the page you want to retrieve the like count for. Once you have the like count data, you can then display it on your webpage using PHP.

<?php
// Specify the URL for which you want to get the like count
$url = 'https://example.com';

// Make a GET request to the Facebook Graph API
$response = file_get_contents('https://graph.facebook.com/?id=' . urlencode($url));
$data = json_decode($response);

// Check if the like count data is available
if(isset($data->share->share_count)){
    $like_count = $data->share->share_count;
    echo 'Like Count: ' . $like_count;
} else {
    echo 'Like Count: 0';
}
?>