diff options
author | Andres Rey <[email protected]> | 2017-11-23 18:46:40 +0000 |
---|---|---|
committer | Andres Rey <[email protected]> | 2017-11-23 18:46:40 +0000 |
commit | 201750d606fae8e03cc425afba1ecb6326dd3f00 (patch) | |
tree | b99ad5f3075da0bd8b831c33523742a2398ac792 /src/HTMLParser.php | |
parent | 1638f5223208e0ed43eed2be25263c5aa149b814 (diff) |
Fix issue #32: Avoid division by zero when title is null.
Diffstat (limited to 'src/HTMLParser.php')
-rw-r--r-- | src/HTMLParser.php | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/HTMLParser.php b/src/HTMLParser.php index 77c68cf..d4d10b9 100644 --- a/src/HTMLParser.php +++ b/src/HTMLParser.php @@ -1048,7 +1048,7 @@ class HTMLParser */ $h2 = $article->getElementsByTagName('h2'); if ($h2->length === 1) { - $lengthSimilarRate = (mb_strlen($h2->item(0)->textContent) - mb_strlen($this->metadata['title'])) / mb_strlen($this->metadata['title']); + $lengthSimilarRate = (mb_strlen($h2->item(0)->textContent) - mb_strlen($this->metadata['title'])) / max(mb_strlen($this->metadata['title']), 1); if (abs($lengthSimilarRate) < 0.5) { if ($lengthSimilarRate > 0) { |