From 21f6c44b054511e1d49f2814be1a101d8b3ceabb Mon Sep 17 00:00:00 2001 From: moodler Date: Tue, 8 Mar 2005 07:45:01 +0000 Subject: [PATCH] New function to remove duplicate entries from an array of filterobjects --- lib/filterlib.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/lib/filterlib.php b/lib/filterlib.php index f902c7e9ff5..2d4d2ca3883 100644 --- a/lib/filterlib.php +++ b/lib/filterlib.php @@ -199,4 +199,30 @@ function filter_phrases ($text, $link_array, $ignoretagsopen=NULL, $ignoretagscl } + + +function filter_remove_duplicates($linkarray) { + + $concepts = array(); // keep a record of concepts as we cycle through + $lconcepts = array(); // a lower case version for case insensitive + + $cleanlinks = array(); + + foreach ($linkarray as $key=>$filterobject) { + if ($filterobject->casesensitive) { + $exists = in_array($filterobject->phrase, $concepts); + } else { + $exists = in_array(strtolower($filterobject->phrase), $lconcepts); + } + + if (!$exists) { + $cleanlinks[] = $filterobject; + $concepts[] = $filterobject->phrase; + $lconcepts[] = strtolower($filterobject->phrase); + } + } + + return $cleanlinks; +} + ?>