PHP code example of fdevs / meta-page

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

    

fdevs / meta-page example snippets



use FDevs\MetaPage\Type\NameType;
use FDevs\MetaPage\Type\PropertyType;
use FDevs\MetaPage\Renderer\PhpRenderer;
use FDevs\MetaPage\MetaFactory;
use FDevs\MetaPage\Type\ImageType;
use FDevs\MetaPage\Type\ListType;


$metaFactory = new MetaFactory();
$description = $metaFactory
    ->createBuilder(ListType::class)
    ->add(NameType::class, ['name' => 'description', 'content' => 'description'])
    ->add(NameType::class, ['name' => 'keywords', 'content' => 'keywords'])
    ->add(PropertyType::class, ['name' => 'locale', 'content' => 'ru'])
    ->getMeta()
;

$ogImage = $metaFactory->create(ImageType::class, [
    'content' => 'http://example.com/rock.jpg',
    'image_type' => 'image/jpg',
    'width' => 300,
    'height' => 300,
]);

$view = $metaFactory->createView($description);
$image = $metaFactory->createView($ogImage);

$renderer = new PhpRenderer();

echo $renderer->render($view); //<meta name="description" content="description"/><meta name="keywords" content="keywords"/><meta property="locale" content="ru"/>
echo $renderer->render($image); //<meta property="og:image" content="http://example.com/rock.jpg"/><meta property="og:image:type" content="image/jpg"/><meta property="og:image:width" content="300"/><meta property="og:image:height" content="300"/>
 bash
$ php composer.phar