2 /***************************************************************************
3 Copyright (c) 2005 - 2010 Marcus Campbell
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 ***************************************************************************/
21 header('Content-Type: text/plain; charset=UTF-8');
22 header('Last-Modified: '. gmdate("D, d M Y H:i:s") .' GMT');
23 header('Cache-Control: no-cache, must-revalidate');
24 require_once 'header.inc.php';
26 function getTitle($url) {
27 $fd = @fopen($url, 'r');
29 $html = fread($fd, 1750);
32 // Get title from title tag
33 preg_match_all('/<title>(.*)<\/title>/si', $html, $matches);
34 $title = $matches[1][0];
36 // Get encoding from charset attribute
37 preg_match_all('/<meta.*charset=([^;"]*)">/i', $html, $matches);
38 $encoding = strtoupper($matches[1][0]);
40 // Convert to UTF-8 from the original encoding
41 if (function_exists('mb_convert_encoding')) {
42 $title = @mb_convert_encoding($title, 'UTF-8', $encoding);
45 if (utf8_strlen($title) > 0) {
48 // No title, so return filename
49 $uriparts = explode('/', $url);
50 $filename = end($uriparts);
59 echo getTitle($_GET['url']);