PHP code example of budry / php-open-graph

1. Go to this page and download the library: Download budry/php-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/ */

    

budry / php-open-graph example snippets


$image = new \Budry\OpenGraph\Objects\Image("https://example.com/image.jpg");
$openGraph = new \Budry\OpenGraph\OpenGraph("Page title", "Page URL", $image);

$article = new \Budry\OpenGraph\Types\Article();
$article->setExpirationDate(new DateTimeImmutable("2022-03-12 12:23:24"))
    ->setModifiedDate(new DateTimeImmutable())
    ->setPublishedDate(new DateTimeImmutable())
    ->setSection("SCI-FI")
$openGraph->setType($article);

foreach ($openGraph->getFields() as $field) {
    echo '<meta property="' . $field->getName() . '" content="' . $field->getContent() . '">'
}
shell
$ composer