Skip to content
PHP Logo

Is it possible to extract the title, image, and text of a linked page for sharing on Facebook using PHP?

Yes, it is possible to extract the title, image, and text of a linked page for sharing on Facebook using PHP. You can achieve this by using PHP libraries like Simple HTML DOM Parser to parse the HTML content of the linked page and extract the necessary information such as the title, image URL, and text. Once you have extracted this information, you can use it to share the link on Facebook.

php
<?php
include('simple_html_dom.php');

$url = 'https://example.com'; // URL of the linked page

$html = file_get_html($url);

$title = $html->find('title', 0)->plaintext;
$image = $html->find('meta[property=og:image]', 0)->content;
$text = $html->find('meta[property=og:description]', 0)->content;

// Now you can use the $title, $image, and $text variables to share the link on Facebook
?>