Php如何从url页面获取元标记名称

Php如何从url页面获取元标记名称,php,meta-tags,Php,Meta Tags,我试图从元标记中获取名称 我得到的元标记如下: $test = get_meta_tags('http://viedemerde.fr'); 然后: echo $test['description']; ... 我有描述,但没有: meta name="description 如何获取此信息?get\u meta\u标记只获取元数据,没有额外的html标记或信息 下面是一段代码,它以您希望的方式获取有关任何网页的所有元和信息: 你应该得到你的meta@$test[“metaTags”][“

我试图从元标记中获取名称

我得到的元标记如下:

$test = get_meta_tags('http://viedemerde.fr');
然后:

echo $test['description'];
...
我有描述,但没有:

meta name="description

如何获取此信息?

get\u meta\u标记只获取元数据,没有额外的html标记或信息

下面是一段代码,它以您希望的方式获取有关任何网页的所有元和信息:

你应该得到你的meta@
$test[“metaTags”][“description”][“html”]

或者你可以用你想要的方式使用它

function getUrlData($url) {
$result = false;

$contents = getUrlContents($url);

if (isset($contents) && is_string($contents)) {
    $title = null;
    $metaTags = null;

    preg_match('/<title>([^>]*)<\/title>/si', $contents, $match);

    if (isset($match) && is_array($match) && count($match) > 0) {
        $title = strip_tags($match[1]);
    }

    preg_match_all('/<[\s]*meta[\s]*name="?' . '([^>"]*)"?[\s]*' . 'content="?([^>"]*)"?[\s]*[\/]?[\s]*>/si', $contents, $match);

    if (isset($match) && is_array($match) && count($match) == 3) {
        $originals = $match[0];
        $names = $match[1];
        $values = $match[2];

        if (count($originals) == count($names) && count($names) == count($values)) {
            $metaTags = array();

            for ($i = 0, $limiti = count($names); $i < $limiti; $i++) {
                $metaTags[$names[$i]] = array(
                    'html' => htmlentities($originals[$i]),
                    'value' => $values[$i]
                );
            }
        }
    }

    $result = array(
        'title' => $title,
        'metaTags' => $metaTags
    );
}
return $result;}


function getUrlContents($url, $maximumRedirections = null, $currentRedirection = 0) {
$result = false;

$contents = @file_get_contents($url);

// Check if we need to go somewhere else

if (isset($contents) && is_string($contents)) {
    preg_match_all('/<[\s]*meta[\s]*http-equiv="?REFRESH"?' . '[\s]*content="?[0-9]*;[\s]*URL[\s]*=[\s]*([^>"]*)"?' . '[\s]*[\/]?[\s]*>/si', $contents, $match);

    if (isset($match) && is_array($match) && count($match) == 2 && count($match[1]) == 1) {
        if (!isset($maximumRedirections) || $currentRedirection < $maximumRedirections) {
            return getUrlContents($match[1][0], $maximumRedirections, ++$currentRedirection);
        }

        $result = false;
    } else {
        $result = $contents;
    }
}

return $contents;}

$test = getUrlData('http://ocsidtechnologies.com');  //Replace  with your URL here
echo '<pre>';print_r($test);
函数getUrlData($url){ $result=false; $contents=getUrlContents($url); if(isset($contents)&&is_字符串($contents)){ $title=null; $metaTags=null; preg_match('/([^>]*)/si',$contents,$match); if(isset($match)&&is_数组($match)&&count($match)>0){ $title=strip_标签($match[1]); } preg\u match \u all(“/”]*)“?[\s]*[\/]?[\s]*>/si',$contents,$match); if(isset($match)&&is_数组($match)&&count($match)==3){ $originals=$match[0]; $names=$match[1]; $values=$match[2]; 如果(计数($originals)=计数($names)&&count($names)=计数($values)){ $metaTags=array(); 对于($i=0,$limiti=count($names);$i<$limiti;$i++){ $metaTags[$names[$i]]=数组( 'html'=>htmlentities($originals[$i]), “值”=>$values[$i] ); } } } $result=数组( “title”=>$title, “metaTags”=>$metaTags ); } 返回$result;} 函数getUrlContents($url,$maximumRedirections=null,$currentRedirection=0){ $result=false; $contents=@file\u get\u contents($url); //看看我们是否需要去别的地方 if(isset($contents)&&is_字符串($contents)){
预赛('/@ShaH:我怎样才能获得所有的元标记,如category wise,这是可能的?@Rathinam我认为上面的代码回答了相同的代码请在本地系统中复制代码并浏览文件以检查或只是将代码粘贴到phpfidle中,然后运行以查看category wise元标记,如author、description、keywords等,我看到了详细信息,我可以知道怎么做吗我可以得到我的所有类别的元标签…像批量出口使用任何东西…@Rathinam你能解释退出正确或打开一个新的线程,如果这不是相关的吗