That's what I was looking for, must have missed the attribute info. Anyway, here is what I've come up with, basically 2 changes:
$pos_open = stripos($line, '<title');
..and..
$start = strpos($line, '>', $pos_open) + 1;
public function getHtmlTitle()
{
// Open the file
try {
$file = $this->openFile();
} catch (Exception $exception) {
return false;
}
// Iterate over each line
foreach ($file as $line) {
// Find the tags
$pos_open = stripos($line, '<title');
$pos_close = strripos($line, '</title>');
// Open and close on the same line
if ($pos_open !== false && $pos_close !== false) {
$start = strpos($line, '>', $pos_open) + 1;
$length = $pos_close - $start;
$title = substr($line, $start, $length);
break;
}
// Open one one line
if ($pos_open !== false) {
$start = strpos($line, '>', $pos_open) + 1;
$title = substr($line, $start);
continue;
}
// Close on one line
if ($pos_close !== false && isset($title)) {
$title .= substr($line, 0, $pos_close);
break;
}
// Continue title if started
if (isset($title)) {
$title .= $line;
}
}
// Title not found
if (!isset($title)) {
return false;
}
// Cleanup and return
$title = trim($title);
$title = str_replace(array("\r\n", "\n\r", "\r", "\n"), ' ', $title);
return $title;
}