]> git.wh0rd.org Git - tt-rss.git/commitdiff
Highlighting search results: Added heuristic approach for common capitalizations...
authorwltb <github.11.el_robb_duderino@spamgourmet.com>
Thu, 1 Aug 2013 11:05:03 +0000 (13:05 +0200)
committerwltb <github.11.el_robb_duderino@spamgourmet.com>
Thu, 1 Aug 2013 11:05:03 +0000 (13:05 +0200)
include/functions.php

index 3aaccbb1936ecfa96bb0590f7c57a3378da1eea3..ea31a40cc06899c6d36ca408a810f1d66e8e9ee4 100644 (file)
 
                                // http://stackoverflow.com/questions/4081372/highlight-keywords-in-a-paragraph
 
-                               $elements = $xpath->query('//*[contains(.,"'.$word.'")]');
+                               $also_query = '';
+                               foreach(array(strtolower($word), strtoupper($word), ucfirst(strtolower($word))) as $word_cap) {
+                                       $also_query .= ' or contains(.,"'.$word_cap.'")' ;
+                               }
+                               $elements = $xpath->query('//*[contains(.,"'.$word.'")' . $also_query . ']');
 
                                foreach ($elements as $element) {
                                        foreach ($element->childNodes as $child) {
 
                                                if (!$child instanceof DomText) continue;
 
-                                               $fragment = $doc->createDocumentFragment();
-                                     $text = $child->textContent;
+                                               $fragment = $doc->createDocumentFragment();
+                                               $text = $child->textContent;
                                                $stubs = array();
 
                                                while (($pos = mb_stripos($text, $word)) !== false) {