如何使用PHP提取URL的标题,图像,关键字和描述


how to extract a url's title, images, keywords and description using php?

可能的重复项:
在 PHP 中检索<标题>的最快方法

假设有一个网站 http://www.example.com 标题="示例"描述="这是一个示例",关键字="示例,问题,爱php"。

在提交链接时可以使用哪些 php 代码或任何其他

代码获取这些代码?
如果你想

从外部链接获取数据,你想使用 curl 获取页面。

下面是一个示例

<?php
$ch = curl_init("http://www.google.nl");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);
$title = preg_match('!<title>(.*?)</title>!i', $result, $matches) ? $matches[1] : 'No title found';
$description = preg_match('!<meta name="description" content="(.*?)">!i', $result, $matches) ? $matches[1] : 'No meta description found';
$keywords = preg_match('!<meta name="keywords" content="(.*?)">!i', $result, $matches) ? $matches[1] : 'No meta keywords found';
echo $title . '<br>';
echo $description . '<br>';
echo $keywords . '<br>';
?>

对于 google.nl,这将返回:

Google
No meta description found
No meta keywords found

元描述和关键字可能需要更多调整才能供您使用。

默认情况下,在 apache 中不安装小旁注 cURL,因此您可能需要先安装。

这是cURL php函数页面:http://nl3.php.net/manual/en/ref.curl.php

您的问题太笼统了,但您需要的工具file_get_contents获取页面,然后正则表达式查找数据。 您可以使用它轻松找到标题,但关键字和描述的确切含义尚不清楚......