Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何提取url';使用php的标题、图像、关键字和描述?_Php_Url_Extract_Digg - Fatal编程技术网

如何提取url';使用php的标题、图像、关键字和描述?

如何提取url';使用php的标题、图像、关键字和描述?,php,url,extract,digg,Php,Url,Extract,Digg,可能重复: 假设有一个网站title=“Example”description=“it is a Example”和keywords=“Example,question,love php” 提交链接时,可以使用什么php代码或任何其他代码获取这些内容?您的问题太笼统了,但您需要的工具是使用file\u get\u contents获取页面,然后使用regex查找数据。您可以使用此工具轻松查找标题,但关键字和描述的确切含义尚不清楚……您的问题过于笼统,但您需要的工具是使用file\u get\u

可能重复:

假设有一个网站title=“Example”description=“it is a Example”和keywords=“Example,question,love php”


提交链接时,可以使用什么php代码或任何其他代码获取这些内容?

您的问题太笼统了,但您需要的工具是使用file\u get\u contents获取页面,然后使用regex查找数据。您可以使用此工具轻松查找标题,但关键字和描述的确切含义尚不清楚……

您的问题过于笼统,但您需要的工具是使用file\u get\u contents获取页面,然后使用regex查找数据。您可以使用此功能轻松查找标题,但您所指的关键字和描述的确切含义尚不清楚……

如果您希望从外部链接获取数据,则需要使用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>';
?>
元描述和关键字可能需要更多的调整,以供您使用

apache中默认情况下未安装Little sidenote cURL,因此您可能需要先安装


下面是cURL 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>';
?>
元描述和关键字可能需要更多的调整,以供您使用

apache中默认情况下未安装Little sidenote cURL,因此您可能需要先安装


下面是cURL php函数页面:

您可以这样获得标题:您可以这样获得标题:他指的是html标题。。看在上帝的份上,不要使用正则表达式他指的是html标题。。看在上帝的份上,不要用正则表达式。。