views:

291

answers:

5

Hello all,

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

+1  A: 

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.

Summer
+1  A: 

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.

modernzombie
+1  A: 

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

Sarfraz
+3  A: 

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>";
Mademoiselle Vagin Cul
I knew about this but forgot about it, I even did a search and found a customised version for codeigniter: http://www.thephpx.com/2009/10/25/php-simple-html-dom-parser-codeigniter-integration/
Abs
A: 

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");
}
Artefacto