I am using codeigniter. I guess it doesn't matter which php framework I am using.
But before I write my own class is there another that has already been written that allows a user to get the page title and meta tags (keywords, descriptions) of any sit...if they have any.
Any sort of PHP class that does that would be great.
Thanks all
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");
}