Read title of a website with PHP

Snippet for reading title of a website.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
function getPageTitle($sURL)
{
    if( ($sHTML = file_get_contents($sURL)) &&
        preg_match("/<title>(.+)<\/title>/i"$sHTML$aTitle))  
    {
        return trim($aTitle[1]);
    }
    return false;
}
echo utf8_decode(getPageTitle("http://sklueh.de"));
/*
 * Ausgabe:
 * Sebastian Klüh | Softwareentwicklung und was mich sonst so beschäftigt.
 */
X

Url: http://sklueh.de/2012/10/titel-einer-webseite-mit-php-auslesen/

Language: PHP | User: sklueh | Created: Sep 24, 2013