PHP code example of jclyons52 / page-preview

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

    

jclyons52 / page-preview example snippets


PreviewManager::create()->fetch('https://somewebsite.com')->render();

$previewManager->render('thumbnail');

$previewManager->fetch('https://somewebsite.com')->render('myAwesomeTemplate', '/path/to/template/directory');

$pool = new Pool();

$previewManager = PreviewManager::create($pool);

$preview = $previewManager->findOrFetch('http://www.example.com/directory');

$previewManager->cache($preview);

$meta = $preview->meta->unFlatten()['twitter'];

[
    "card" => "app",
    "site" => "@TwitterDev",
    "description" => "Cannonball is the fun way to create and share stories and poems on your phone. Start with a beautiful image from the gallery, then choose words to complete the story and share it with friends.",
    "app" => [
        "country" => "US",
        "name" => [
            "iphone" => "Cannonball",
            "ipad" => "Cannonball",
            "googleplay" => "Cannonball",
        ],
        "id" => [
            "iphone" => "929750075",
            "ipad" => "929750075",
            "googleplay" => "io.fabric.samples.cannonball",
        ],
        "url" => [
            "iphone" => "cannonball://poem/5149e249222f9e600a7540ef",
            "ipad" => "cannonball://poem/5149e249222f9e600a7540ef",
            "googleplay" => "http://cannonball.fabric.io/poem/5149e249222f9e600a7540ef",
        ],
    ]

];
 php
$previewManager = PreviewManager::create();
$preview = $previewManager->fetch('https://somewebsite.com');
echo $preview->render(); // returns bootstrap media link preview
echo $preview->toJson(); // returns json string of preview attributes