Re: [PHP] Case issue with eregi_replace in text highlight function

2006-02-22 Thread Chris



Here is the function:

function highlight_text($text, $highlight) {
return eregi_replace($highlight, span class=highlight . $highlight .
/span, $text);
}

In this case, if the  text to highglight is:

MacOS X Super Gizmo

And a client searches for the string macos, the result will be: 


span class=highlightmacos/span X Super Gizmo


You're using the eregi_replace function - which does case insensitive 
replaces (read the man page).


Change it to use

ereg_replace

--
Postgresql  php tutorials
http://www.designmagick.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Case issue with eregi_replace in text highlight function

2006-02-22 Thread Nicolas Verhaeghe
That's not where the issue is.

Eregi_replace conducts a case insensitive SEARCH but how the REPLACE
operates has nothing to do with it.

If you use ereg_replace, then it is most obviously not going to replace
MacOS with span class=highlightmacos/span or even span
class=highlightMacOS/span, because the string searched for is of a
different case.

But thanks for helping.

-Original Message-
From: Chris [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, February 22, 2006 5:39 PM
To: Nicolas Verhaeghe
Cc: php-general@lists.php.net
Subject: Re: [PHP] Case issue with eregi_replace in text highlight
function



 Here is the function:
 
 function highlight_text($text, $highlight) {
 return eregi_replace($highlight, span class=highlight . $highlight

 . /span, $text); }
 
 In this case, if the  text to highglight is:
 
 MacOS X Super Gizmo
 
 And a client searches for the string macos, the result will be:
 
 span class=highlightmacos/span X Super Gizmo

You're using the eregi_replace function - which does case insensitive 
replaces (read the man page).

Change it to use

ereg_replace

-- 
Postgresql  php tutorials
http://www.designmagick.com/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Case issue with eregi_replace in text highlight function

2006-02-22 Thread Chris

Nicolas Verhaeghe wrote:

That's not where the issue is.

Eregi_replace conducts a case insensitive SEARCH but how the REPLACE
operates has nothing to do with it.

If you use ereg_replace, then it is most obviously not going to replace
MacOS with span class=highlightmacos/span or even span
class=highlightMacOS/span, because the string searched for is of a
different case.


Good point, I had it around the wrong way.


function highlight_text($text, $highlight) {
  return eregi_replace($highlight, span class=highlight . $highlight
. /span, $text);
}


So where does 'highlight' come from when you pass it in ?

--
Postgresql  php tutorials
http://www.designmagick.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Case issue with eregi_replace in text highlight function

2006-02-22 Thread Chrome
How about

function highlight_text($text, $highlight) {
   return preg_replace('/(' . $highlight . ')/i', 'span
class=highlight$1/span', $text); 
}

Case should be retained and the search is case insensitive

HTH

Dan
---
http://chrome.me.uk
 

-Original Message-
From: Nicolas Verhaeghe [mailto:[EMAIL PROTECTED] 
Sent: 23 February 2006 00:55
To: 'Chris'
Cc: php-general@lists.php.net
Subject: RE: [PHP] Case issue with eregi_replace in text highlight function

That's not where the issue is.

Eregi_replace conducts a case insensitive SEARCH but how the REPLACE
operates has nothing to do with it.

If you use ereg_replace, then it is most obviously not going to replace
MacOS with span class=highlightmacos/span or even span
class=highlightMacOS/span, because the string searched for is of a
different case.

But thanks for helping.

-Original Message-
From: Chris [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, February 22, 2006 5:39 PM
To: Nicolas Verhaeghe
Cc: php-general@lists.php.net
Subject: Re: [PHP] Case issue with eregi_replace in text highlight
function



 Here is the function:
 
 function highlight_text($text, $highlight) {
 return eregi_replace($highlight, span class=highlight . $highlight

 . /span, $text); }
 
 In this case, if the  text to highglight is:
 
 MacOS X Super Gizmo
 
 And a client searches for the string macos, the result will be:
 
 span class=highlightmacos/span X Super Gizmo

You're using the eregi_replace function - which does case insensitive 
replaces (read the man page).

Change it to use

ereg_replace

-- 
Postgresql  php tutorials
http://www.designmagick.com/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


__ NOD32 1.1416 (20060222) Information __

This message was checked by NOD32 antivirus system.
http://www.eset.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Case issue with eregi_replace in text highlight function

2006-02-22 Thread Nicolas Verhaeghe
This does not highlight anything... Sorry!

Thanks for the help

-Original Message-
From: Chrome [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, February 22, 2006 6:19 PM
To: 'Nicolas Verhaeghe'; 'Chris'
Cc: php-general@lists.php.net
Subject: RE: [PHP] Case issue with eregi_replace in text highlight
function


How about

function highlight_text($text, $highlight) {
   return preg_replace('/(' . $highlight . ')/i', 'span
class=highlight$1/span', $text); 
}

Case should be retained and the search is case insensitive

HTH

Dan
---
http://chrome.me.uk
 

-Original Message-
From: Nicolas Verhaeghe [mailto:[EMAIL PROTECTED] 
Sent: 23 February 2006 00:55
To: 'Chris'
Cc: php-general@lists.php.net
Subject: RE: [PHP] Case issue with eregi_replace in text highlight
function

That's not where the issue is.

Eregi_replace conducts a case insensitive SEARCH but how the REPLACE
operates has nothing to do with it.

If you use ereg_replace, then it is most obviously not going to replace
MacOS with span class=highlightmacos/span or even span
class=highlightMacOS/span, because the string searched for is of a
different case.

But thanks for helping.

-Original Message-
From: Chris [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, February 22, 2006 5:39 PM
To: Nicolas Verhaeghe
Cc: php-general@lists.php.net
Subject: Re: [PHP] Case issue with eregi_replace in text highlight
function



 Here is the function:
 
 function highlight_text($text, $highlight) {
 return eregi_replace($highlight, span class=highlight . $highlight

 . /span, $text); }
 
 In this case, if the  text to highglight is:
 
 MacOS X Super Gizmo
 
 And a client searches for the string macos, the result will be:
 
 span class=highlightmacos/span X Super Gizmo

You're using the eregi_replace function - which does case insensitive 
replaces (read the man page).

Change it to use

ereg_replace

-- 
Postgresql  php tutorials
http://www.designmagick.com/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


__ NOD32 1.1416 (20060222) Information __

This message was checked by NOD32 antivirus system. http://www.eset.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php