Jump to content

Should I use regex to get website page title tag, description, keywords contents


2levelsabove

Recommended Posts

The answer depends on your proficiencies and the tools available to you. For example, regex might be easier for you to pick up and write a quick script doing what you want (get those tags' contents). For me, it might be easier to use a document parser and access the structure (e.g using Tidy, DOM and friends) to get at the tags' contents.  For someone else, get_meta_tags() might work fine (assuming they were not wanting the title!).

 

If you're not comfortable with one method over another (or not aware of others to compare against) then that's also going to come into play with regards to the "easiest" way to do something.

Thanks a lot for your quick response.

 

One last thing however. What are some document parsers that you like? I know you mentioned Tidy. Any other recommendations?

 

Thanks again!

I like to use Tidy to clean up the potentially messy HTML (a lot of the web is very messy!) and DOMDocument for parsing into something I can query and get the required information in PHP.

 

There are many branches from there; like Zend Framework's Zend_Dom_Query which uses DOM/XPath behind the scenes. There are even wrappers around regex-scraping if you wanted to go in that direction (but really, don't unless you have very specific reasons to do so).

  • 1 year later...
  • 2 weeks later...

I've just created an article on How to Parse Title Description Keywords From A Website with PHP and I would like to share: http://4rapiddev.com/php/php-parse-title-description-keywords-from-a-website/

 

That article is a great demonstration of what people should not be doing! As already noted, there are far more robust and useful tools available than hacking together a bunch of regular expressions; so, use those. :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.