Merge pull request #513 from ArthurHoaro/hotfix/retrieve-title-issue
Fixes #512: retrieving title didn't match the first closing tag
This commit is contained in:
commit
5816801b15
2 changed files with 3 additions and 1 deletions
|
@ -9,7 +9,7 @@
|
||||||
*/
|
*/
|
||||||
function html_extract_title($html)
|
function html_extract_title($html)
|
||||||
{
|
{
|
||||||
if (preg_match('!<title>(.*)</title>!is', $html, $matches)) {
|
if (preg_match('!<title>(.*?)</title>!is', $html, $matches)) {
|
||||||
return trim(str_replace("\n", ' ', $matches[1]));
|
return trim(str_replace("\n", ' ', $matches[1]));
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -15,6 +15,8 @@ public function testHtmlExtractExistentTitle()
|
||||||
$title = 'Read me please.';
|
$title = 'Read me please.';
|
||||||
$html = '<html><meta>stuff</meta><title>'. $title .'</title></html>';
|
$html = '<html><meta>stuff</meta><title>'. $title .'</title></html>';
|
||||||
$this->assertEquals($title, html_extract_title($html));
|
$this->assertEquals($title, html_extract_title($html));
|
||||||
|
$html = '<html><title>'. $title .'</title>blabla<title>another</title></html>';
|
||||||
|
$this->assertEquals($title, html_extract_title($html));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue