aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorz0rglub <z0rglub@piwigo.org>2004-03-31 22:25:31 +0000
committerz0rglub <z0rglub@piwigo.org>2004-03-31 22:25:31 +0000
commit2c860657f45a9789f4ee7b4f496fff624bb8404f (patch)
treedca7b82ef98dc70d5bf1d3d7a22d4995f4ed66f9
parentd74a116ded82bbd98683fe2c859a84a8c300ac83 (diff)
bug 23 : search case insensitive BUT highlightning case sensitive
git-svn-id: http://piwigo.org/svn/trunk@409 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to '')
-rw-r--r--include/functions.inc.php25
1 files changed, 17 insertions, 8 deletions
diff --git a/include/functions.inc.php b/include/functions.inc.php
index bef133253..4337cf81a 100644
--- a/include/functions.inc.php
+++ b/include/functions.inc.php
@@ -278,10 +278,17 @@ function get_languages( $rep_language )
return $languages;
}
-// - add_style replaces the
-// $search into <span style="$style">$search</span>
-// in the given $string.
-// - The function does not replace characters in HTML tags
+/**
+ * replaces the $search into <span style="$style">$search</span> in the
+ * given $string.
+ *
+ * case insensitive replacements, does not replace characters in HTML tags
+ *
+ * @param string $string
+ * @param string $search
+ * @param string $style
+ * @return string
+ */
function add_style( $string, $search, $style )
{
//return $string;
@@ -295,15 +302,17 @@ function add_style( $string, $search, $style )
while ( is_numeric( $start ) and is_numeric( $end ) )
{
$treatment = substr ( $remaining, 0, $start );
- $treatment = str_replace( $search, '<span style="'.$style.'">'.
- $search.'</span>', $treatment );
+ $treatment = preg_replace( '/('.$search.')/i',
+ '<span style="'.$style.'">\\0</span>',
+ $treatment );
$return_string.= $treatment.substr( $remaining, $start, $end-$start+1 );
$remaining = substr ( $remaining, $end + 1, strlen( $remaining ) );
$start = strpos ( $remaining, '<' );
$end = strpos ( $remaining, '>' );
}
- $treatment = str_replace( $search, '<span style="'.$style.'">'.
- $search.'</span>', $remaining );
+ $treatment = preg_replace( '/('.$search.')/i',
+ '<span style="'.$style.'">\\0</span>',
+ $remaining );
$return_string.= $treatment;
return $return_string;