sanitize title better
authorChristian Weiske <cweiske@cweiske.de>
Thu, 11 Feb 2016 16:37:12 +0000 (17:37 +0100)
committerChristian Weiske <cweiske@cweiske.de>
Thu, 11 Feb 2016 16:37:12 +0000 (17:37 +0100)
src/phinde/Helper.php
src/phinde/LinkExtractor/Html.php

index 40ea751442a2b62eb17e84a09694b5abbe41d34b..312c5e54a35ba4790c15842ca349504f241468ac 100644 (file)
@@ -30,5 +30,16 @@ class Helper
         }
         return 'http://' . $url;
     }
         }
         return 'http://' . $url;
     }
+
+    public static function sanitizeTitle($str)
+    {
+        return trim(
+            str_replace(
+                array("\r", "\n", '  ', '  '),
+                array('', ' ', ' ', ' '),
+                $str
+            )
+        );
+    }
 }
 ?>
 }
 ?>
index 4acd19f513017b1eff58c1e49b61763c62fdf184..a6fa8efef8fe9725722bf94bbd137671b73e3afe 100644 (file)
@@ -2,6 +2,7 @@
 namespace phinde\LinkExtractor;
 
 use phinde\LinkInfo;
 namespace phinde\LinkExtractor;
 
 use phinde\LinkInfo;
+use phinde\Helper;
 
 class Html
 {
 
 class Html
 {
@@ -36,10 +37,10 @@ class Html
         $links = $dx->evaluate('//a');
         //FIXME: link rel, img, video
 
         $links = $dx->evaluate('//a');
         //FIXME: link rel, img, video
 
-        $alreadySeen = array();
+        $alreadySeen = array($url => true);
 
         foreach ($links as $link) {
 
         foreach ($links as $link) {
-            $linkTitle = $link->textContent;
+            $linkTitle = Helper::sanitizeTitle($link->textContent);
             $href = '';
             foreach ($link->attributes as $attribute) {
                 if ($attribute->name == 'href') {
             $href = '';
             foreach ($link->attributes as $attribute) {
                 if ($attribute->name == 'href') {