[Phpwm] help with function
phil at infolinkelectronics.co.uk
Fri Mar 23 08:48:53 GMT 2007
> On Fri, 23 Mar 2007 02:13:50 -0000, Phil Beynon
> <phil at infolinkelectronics.co.uk> wrote:
> > It works just about perfectly, and I've been using for some time.
> > Except last night I searched on '.' and discovered if that's done it
> > replaces every char in the data variable with the same number
> of .s - all
> > nicely highlighted, and I cannot for the life of me see why.
> You probably want to run the search-term through preg_quote to
> escape the
> . (and any other RE characters): http://uk2.php.net/preg-quote
That was the sort of approach I was trying, but it didnt seem to work as it should or at least as I expected it to.
Then I was having a think about the fact that eregi() was regular expression based and came across a command that I don't think I'd ever seen before called quotemeta() which explicitly escapes regular expression characters.
So changing the $search part of the eregi() to:
$textarr[$key] = eregi_replace(quotemeta($search),"<FONT style=\"BACKGROUND-COLOR: #ff0000\">" . $search . "</FONT>",$value);}}
Fixed it and it now gives consistent, and more importantly expected, results.
More information about the Phpwm