PHP code example of iamfredric / open-graph

1. Go to this page and download the library: Download iamfredric/open-graph library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

iamfredric / open-graph example snippets




use Iamfredric\OpenGraph\OpenGraph;

// Request open graph meta from an url
$items = (new OpenGraph())->url('https://example.com'); 

// Get the image
$imageUrl = $items->get('image');
$title = $items->get('image');

// Or just play with the data as an array
$items->toArray();



$client = new class implements \Iamfredric\OpenGraph\Contracts\Clients\Client
{
    public function get(string $url): string
    {
        return file_get_contents($url);
    }
}

new \Iamfredric\OpenGraph\OpenGraph($client);