How to extract the title and meta description using Simple HTML Dom Parser

by KishPress on September 10, 2010

Simple HTML Dom is an excellent script in PHP to play with HTML in an easy and efficient way. I have used this script in a couple of my projects. Recently I was using this script in a customized version of Kish Twit Pro where I wanted to crawl through the tweeted URL and get some information from that page.

I was facing some problem get the

meta description

tag of an URL. I tried Googling initially, but could not find a solution and this worked for me.


include_once('simple_html_dom.php');
$html = new simple_html_dom();
$html->load_file($surl);
foreach($html->find('title') as $element) {
$title = $element->plaintext;
}
foreach($html->find('meta[name=description]') as $element) {
$desc = $element->content;
}
include_once('simple_html_dom.php');	 $html = new simple_html_dom();	 $html->load_file($surl);	 foreach($html->find('title') as $element) {	 $title = $element->plaintext;	 }	 foreach($html->find('meta[name=description]') as $element) { $desc = $element->content;	 }

An alternative way is to use the

get_meta_tags($url)

You can download the Simple HTML Dom Parser Script here.

You can download the Simple HTML Dom Parser Script here.

Related posts:

  1. All in One Seo Plugin and Twenty Ten Theme : Issue with Title when Re-Write Title Enabled After upgrading to WordPress 3.0, I changed my theme to...
  2. Taking care of your WordPress Blog Search Engine Optimization I have been using WordPress for more than 6 years...
  3. Registering a Twitter Application Twitter has a feature where you can write your own...
  4. Tweeting from Google Reader Google Reader is something what I use to aggregate all...

Leave a Comment

Previous post:

Next post: