Detect language of a web page


I want to determine language of a webpage. I researched and found a couple of things:

There are 3 different ways that is used to mention the language:

  1. the HTML tag
<html lang="en">


  1. In XHTML, the language is declared inside the <html> tag as follows:
<html xmlns="" lang="en" xml:lang="en">

  1. The meta tag
<meta http-equiv="Content-Language" content="ru"/>

Is there any other way ? Can any use use preg_match and give me a code/function that give me the language code ? (en, ru, gr, fr,etc etc) ?

Best Regards