PHP code example of ones006 / link-preview

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

    

ones006 / link-preview example snippets


use LinkPreview\LinkPreview;

$linkPreview = new LinkPreview('http://github.com');
$parsed = $linkPreview->getParsed();
foreach ($parsed as $parserName => $link) {
    echo $parserName . PHP_EOL . PHP_EOL;

    echo $link->getUrl() . PHP_EOL;
    echo $link->getRealUrl() . PHP_EOL;
    echo $link->getTitle() . PHP_EOL;
    echo $link->getDescription() . PHP_EOL;
    echo $link->getImage() . PHP_EOL;
    print_r($link->getPictures());
}

use LinkPreview\LinkPreview;
use LinkPreview\Model\VideoLink;

$linkPreview = new LinkPreview('https://www.youtube.com/watch?v=8ZcmTl_1ER8');
$parsed = $linkPreview->getParsed();
foreach ($parsed as $parserName => $link) {
    echo $parserName . PHP_EOL . PHP_EOL;

    echo $link->getUrl() . PHP_EOL;
    echo $link->getRealUrl() . PHP_EOL;
    echo $link->getTitle() . PHP_EOL;
    echo $link->getDescription() . PHP_EOL;
    echo $link->getImage() . PHP_EOL;
    if ($link instanceof VideoLink) {
        echo $link->getVideoId() . PHP_EOL;
        echo $link->getEmbedCode() . PHP_EOL;
    }
}