Bunun için herhangi bir kitaplık gördüm, ama oldukça basit bir şey görünüyor değil. Ben size yardımcı olabilir hızlı bir fonksiyonu aşağı zerre ettik. Ben basit, vb, bazı hata işleme koymak, içeriğini getirmek için cURL kullanmak isteyebilirsiniz tutmuş
Her neyse, burada benim iki sent:
<?php
function getLinkInfo($url)
{
// Get target link html
$html = file_get_contents($url);
// Prepare the DOM document
$dom = new DOMDocument();
$dom->loadHTML($html);
$dom->preserveWhiteSpace = false;
// Get page title
$titles = $dom->getElementsByTagname('title');
foreach ($titles as $title) {
$linkTitle = $title->nodeValue;
}
// Get META tags
$metas = $dom->getElementsByTagname('meta');
// We only need description
foreach ($metas as $meta) {
if ($meta->getAttribute("name") == "description") {
$linkDesc = $meta->getAttribute("content");
}
}
// Get all images
$imgs = $dom->getElementsByTagname('img');
// Again, we need the first one only
foreach ($imgs as $img) {
$firstImage = $img->getAttribute("src");
if (strpos("http://", $firstImage) === false) {
$firstImage = $url . $firstImage;
}
break;
}
$output = <<<HTML
<div class="info">
<div class="image"><img src="{$firstImage}" alt="{$linkTitle}" /></div>
<div class="desc">
<div class="title">{$linkTitle}</div>
<div class="subtitle">{$url}</div>
<div class="summary">{$linkDesc}</div>
</div>
</div>
HTML;
return $output;
}
echo getLinkInfo("http://www.phpfour.com/");