PHP code example of aipng / open-graph

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

    

aipng / open-graph example snippets


use AipNg\OpenGraph\OpenGraph;
use AipNg\OpenGraph\MetaTags;
use AipNg\OpenGraph\MetaType;
use AipNg\ValueObjects\Web\Url;

$og = new OpenGraph;

$og
	->title('title')
	->type(MetaType::WEBSITE)
	->url(Url::from('https://site.com'))
	->image(Url::from('https://site.com/image.jpg'), 100, 200, 'image/jpg')
	->description('description')
	->siteName('site name');

var_dump($og->hasTag(MetaTags::OG_TITLE)); // true

$og->toArray();

use AipNg\OpenGraph\OpenGraph;

$og = new OpenGraph;

$og->article('title', new \DateTimeImmutable('2020-01-02 12:13:14'), 'section', ['tag-1', 'tag-2']);

$og->toArray();

/**
[
    'og:title' => 'title',
    'og:type' => 'article',
    'article:published_time' => '2020-01-02T12:13:14+0100',
    'article:section' => 'section',
    'article:tag' => [
        'tag-1',
        'tag-2',
    ],
];
*/