Revision 438
Added by Matthias over 17 years ago
trunk/wb/framework/frontend.functions.php | ||
---|---|---|
68 | 68 |
|
69 | 69 |
//function to highlight search results |
70 | 70 |
function search_highlight($foo='', $arr_string=array()) { |
71 |
$last_string=""; |
|
71 | 72 |
foreach($arr_string as $string) { |
72 |
$string=str_replace('\\','\\\\',$string); |
|
73 |
$string=str_replace('/','\/',$string); |
|
74 |
$string=str_replace('*','\*',$string); |
|
75 |
$string=str_replace('.','\.',$string); |
|
76 |
|
|
77 |
$foo=preg_replace('/(>[^<]*)('.strtolower($string).')/', '$1<span class="highlight">$2</span>',$foo); |
|
78 |
$foo=preg_replace('/^([^<]*)('.strtolower($string).')/', '$1<span class="highlight">$2</span>',$foo); |
|
79 |
|
|
80 |
$foo=preg_replace('/(>[^<]*)('.strtoupper($string).')/', '$1<span class="highlight">$2</span>',$foo); |
|
81 |
$foo=preg_replace('/^([^<]*)('.strtoupper($string).')/', '$1<span class="highlight">$2</span>',$foo); |
|
82 |
|
|
83 |
$foo=preg_replace('/(>[^<]*)('.ucfirst($string).')/', '$1<span class="highlight">$2</span>',$foo); |
|
84 |
$foo=preg_replace('/^([^<]*)('.ucfirst($string).')/', '$1<span class="highlight">$2</span>',$foo); |
|
73 |
// filter meta-characters |
|
74 |
$string=preg_quote($string, '/'); |
|
75 |
if ($string!=$last_string ) { |
|
76 |
$foo=preg_replace('/('.$string.')(?=[^>;]*(&|<))/iUS', '<span class="highlight">$1</span>',$foo); |
|
77 |
$last_string=$string; |
|
78 |
} |
|
85 | 79 |
} |
86 | 80 |
return $foo; |
87 | 81 |
} |
Also available in: Unified diff
Fixed some issues in search highlighting function (Thanks to thorn)