-----Original Message-----
From: Gabe
Sent: Friday, June 25, 2004, 9:06:15 PM
> Philip Olson wrote:

>>>>>There's a number of functions in PHP that will give me the position of
>>>>>the *first* instance of the matched string, but it doesn't look like the
>>>>>function would keep searching after the first match.  Anyway, am I
>>>>>overlooking a function that already has the functionality that I'm
>>>>>searching for?  Or does anyone have any ideas how I can accomplish this
>>>>>efficiently since my search strings can be quite long?
>>>>
>>>>
>>>>try this
>>>>
>>>>preg_replace('/(weather)/i', "<strong>$1</strong>", 'This is the worst
>>>>weather ever.  Weather around
>>>>here is terrible. ')
>>>
>>>Thanks Matt.  I think that will do the trick.  Let me see if I 
>>>understand it correctly.  the "i" will make the search case-INsensitive,
>>>and the parenthesis around "weather" will store what it finds in the
>>>variable $1?  Is that right?
>> 
>> 
>> Also consider str_replace() as it's faster albeit case
>> sensitive.  str_ireplace() exists in PHP 5.  Just another
>> option, I'm surprised you didn't find it when looking
>> around strpos() and friends.
>> 
>> Your assumptions above are correct, sorry Matt for stepping
>> in! :)  I prefer cold weather.
>> 
>> Regards,
>> Philip

> Thanks Philip.  I did notice str_replace() but it didn't look like I
> could use it without it actually replacing what it found instead of just
> adding strings before and after it.  Am I wrong?

I'd say it will do the job just fine if case sensitivity is not an
issue:

$word = 'weather';
$new = str_replace($word, "<strong>$word</strong>", $phrase);

... speaks for itself ;)

/rh

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

Reply via email to