Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extract title and meta description using PHP Simple HTML DOM Parser?

How can I extract a page's title and meta description using the PHP Simple HTML DOM Parser?

I just need the title of the page and the keywords in plain text.

like image 478
Henry The Least Avatar asked Jul 08 '12 18:07

Henry The Least


3 Answers

$html->find('meta[name=keywords]',0)->attr['content'];
$html->find('meta[name=description]',0)->attr['content'];
like image 140
Алексей Склейнов Avatar answered Sep 30 '22 03:09

Алексей Склейнов


$html = new simple_html_dom();
$html->load_file('some_url'); 

//To get Meta Title
$meta_title = $html->find("meta[name='title']", 0)->content;

//To get Meta Description
$meta_description = $html->find("meta[name='description']", 0)->content;

//To get Meta Keywords
$meta_keywords = $html->find("meta[name='keywords']", 0)->content;

NOTE: The names of meta tags are casesensitive!

like image 34
Faraona Avatar answered Sep 30 '22 03:09

Faraona


you can using php code and so simple to know. like here

$result = 'site.com'; $tags = get_meta_tags("html/".$result);

like image 33
Sinatrya Yogi Rizal Avatar answered Sep 30 '22 04:09

Sinatrya Yogi Rizal