Forum Moderators: coopster

Message Too Old, No Replies

case insensitive preg_replace?

how do I do it...

         

dmmh

9:43 am on Feb 7, 2005 (gmt 0)

10+ Year Member



something is wrong with my highlighting, the first search result is for 'er' the second is for 'Er', same results, but no highlighting for the second query :S

vice versa this will not highlight capitalised matches :(

code:

$body = html_entity_decode(nl2br(stripslashes($myresult['message']))); $body = preg_replace("/$value/","<span class=\"highlight\">$value</span>",$body); echo $body;?>

[edited by: coopster at 12:25 pm (utc) on Feb. 7, 2005]
[edit reason] removed urls [/edit]

mincklerstraat

11:15 am on Feb 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



you need to use the regex "modifier" i by adding it to the end of your regular expression (after the last delimiter) -

like:

preg_replace("/$value/i","<span class=\"highlight\">$value</span>",$body);

nb. you might want to get rid of the links to those images since links to just about anything on your own site is sorta frowned upon and a mod will delete it. btw, what's that 'Find' stuff there on the bottom of firefox? Is it an extension that's worth trying out?

dmmh

12:19 pm on Feb 7, 2005 (gmt 0)

10+ Year Member



press ctrl-f dood :)

and thanks for the help....cant edit out images..cant edit my post anymore :(

dmmh

12:22 pm on Feb 7, 2005 (gmt 0)

10+ Year Member



mmm, if I use that, it also echoes it out capitalised...which isnt quite what I want

I just want it to leave alone the formatting but do a case-insensitive preg_replace. any ideas?

coopster

12:27 pm on Feb 7, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Use pattern matching.
preg_replace("/($value)/i","<span class=\"highlight\">$1</span>",$body);
note the parenthesis and the backreference variable

minck, you have to have version >= 1.0 of Fx to get that feature I believe ...

dmmh

12:31 pm on Feb 7, 2005 (gmt 0)

10+ Year Member



awesome, thanks.

Yeah Im on 1.0, my first usage of Firefox, didnt realise older versions dont have it