PHP code example of chriskonnertz / open-graph

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

    

chriskonnertz / open-graph example snippets


'aliases' => [
    ...
    'OpenGraph' => 'ChrisKonnertz\OpenGraph\OpenGraph',
],

'aliases' => [
    ...
    'OpenGraph' => 'ChrisKonnertz\OpenGraph\OpenGraphFacade',
],

...

'providers' => [
    ...
    'ChrisKonnertz\OpenGraph\OpenGraphServiceProvider',
],

$og = OpenGraph::title('Apple Cookie')
    ->type('article')
    ->image('http://example.org/apple.jpg')
    ->description('Welcome to the best apple cookie recipe never created.')
    ->url();

$og->title('Apple Cookie')
    ->type('article')
    ->description('A delicious recipe')
    ->url()
    ->locale('en_US')
    ->localeAlternate(['en_UK'])
    ->siteName('Cookie Recipes Website')
    ->determiner('an');

$og->image($imageUrl, [
    'width'     => 300,
    'height'    => 200
]);

$og->audio($audioUrl, [
    'type'     => 'audio/mpeg'
]);

$og->video($videoUrl, [
    'width'     => 300,
    'height'    => 200,
    'type'      => 'application/x-shockwave-flash'
]);

$og->article([
    'author'        => 'Jane Doe'
]);

$og->book([
    'author'        => 'John Doe'
]);

$og->profile([
    'first_name'    => 'Kim',
    'last_name'     => 'Doe'
]);

$og->attributes('product', ['product:color' => 'red']);

$og->attributes('product', ['product:color' => 'red'], ['product:color']);

$og->image('http://example.org/apple.jpg')
    ->image('http://example.org/tree.jpg');

$og->validate();

$og = new OpenGraph(true);

$og->validate(false);

$hasTitle = $og->has('title');

$og->forget('title');

$og->clear();

$og->tag('apples', 7);

$tag = $og->lastTag('image');
$value = $tag['value'];