$add_length = floor((($max_length - $total_len) / count($offsets)) / 2);
}
-
+ $lengths = array();
foreach ($offsets as $i => $offset) {
$limit = $limits[$i];
if ($offset == 0 && $add_length) {
}
$substrings[] = $string;
+ $lengths[] = strlen($string);
}
+ // sort by length of context.
+ asort($lengths);
+
$matched = '';
- foreach ($substrings as $string) {
+ foreach ($lengths as $i => $len) {
+ $string = $substrings[$i];
+
if (strlen($matched) + strlen($string) < $max_length) {
$matched .= $string;
}
}
+ $i = 1;
foreach ($words as $word) {
$search = "/($word)/i";
- $replace = "<strong class=\"searchMatch\">$1</strong>";
+ $replace = "<strong class=\"searchMatch searchMatchColor$i\">$1</strong>";
$matched = preg_replace($search, $replace, $matched);
+ $i++;
}
return $matched;
background-color: #FFFF66;
}
+.searchMatchColor1 {
+ background-color: #FFFF66;
+}
+
+.searchMatchColor2 {
+ background-color: #A0FFFF;
+}
+
+.searchMatchColor3 {
+ background-color: #FF9999;
+}
+
+.searchMatchColor4 {
+ background-color: #FF66FF;
+}
+
+.searchMatchColor5 {
+ background-color: #99FF99;
+}
+
+
.searchTitle {
text-decoration: underline;
}