CodeIgniter: A Class/Library to help get meta tags from a web page?

混江龙づ霸主 提交于 2019-11-28 00:31:21

You should have a look at this class: PHP Simple HTML DOM it works this way:

include('simple_html_dom.php');
$html = file_get_html('http://www.codeigniter.com/');

echo $html->find('title', 0)->innertext; // get <title>

echo "<pre>";
foreach($html->find('meta') as $element)
       echo $element->name . " : " . $element->content  . '<br>'; //prints every META tag

echo "</pre>";

Use PHP's curl library. It can pull other pages from the web and fetch them as strings, and then you can parse the string with regular expressions to find the page's title and meta tags.

You can get all the meta tags froma remote page with get_meta_tags - http://ca3.php.net/get_meta_tags

this page has a class to get the page and description, they are also using get_meta_tags - http://www.emirplicanic.com/php/get-remote-page-title-with-php.php

You should be able to combine bits from both to get everything you need.

See this please. This is generic class to get page meta tags and do a lot more. See if you can add this in codeigniter library. Thanks

With DOM/xpath

libxml_use_internal_errors(true);
$c = file_get_contents("http://url/here");
$d = new DomDocument();
$d->loadHTML($c);
$xp = new domxpath($d);
foreach ($xp->query("//meta[@name='keywords']") as $el) {
    echo $el->getAttribute("content");
}
foreach ($xp->query("//meta[@name='description']") as $el) {
    echo $el->getAttribute("content");
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!