Answers for "php link preview like facebook"

PHP
1

php Previewing External Pages like Facebook

require_once('OpenGraph.php');

     $graph = OpenGraph::fetch($url);
/*
            echo "<br>" . "Title: " . $graph->title . "<br>";                // Getting started with Facebook Open Graph
            echo "Site name: " . $graph->siteName . "<br>";         // YouTube
            echo "Description: " . $graph->description . "<br>";    // Originally recorded at the Facebook World ...
            echo "Canonical URL: " . $graph->url . "<br>";          // http://www.youtube.com/watch?v=P422jZg50X4
            echo "Image Url: " . $graph->image . "<br>";
            // Images
            $image = $graph->images[0];
            echo "Image[0] URL: " . $image->url . "<br>";            // https://i1.ytimg.com/vi/P422jZg50X4/maxresdefault.jpg
            echo "Image[0] height: " . $image->height . "<br>";       // null (May return height in pixels on other pages)
            echo "Image[0] width: " . $image->width . "<br>";         // null (May return width in pixels on other pages)

            // Videos
            $video = $graph->videos[0];
            echo "Video URL: " . $video->url . "<br>";        // http://www.youtube.com/v/P422jZg50X4?version=3&autohide=1
            echo "Video height: " . $video->height . "<br>";       // 1080
            echo "Video width: " . $video->width . "<br>";      // 1920
            echo "Video type: " . $video->type . "<br>";      // application/x-shockwave-flash
*/
             var_dump($graph->keys());
             var_dump($graph->schema);
             foreach ($graph as $key => $value) {
                 echo "$key => $value" . "<br><br>";
             }
/*   // more mods 
            $graph = OpenGraph::fetch($url);
            echo '<img src="'. $graph->image.'" width="25%" height="25%"/>';
            echo "<br>".$graph->title . "<br>";                
           // echo "Site name: " . $graph->siteName . "<br>";         
            echo "<br>" . $graph->description . "<br>";   
*/


https://github.com/scottmac/opengraph
alts https://ogp.me/
Posted by: Guest on January-28-2021

Browse Popular Code Answers by Language