What I'm trying to do is find a substring in a much longer string and insert another string before and after the substring. For example:

string to find: weather

string to search in: "This is the worst weather ever. Weather around here is terrible."

string to add before: <strong>
string to add after: </strong>

I can't do a simple search and replace, because I need to maintain the case sensitivity of the word that's in the searched string. So I was hoping to find something that would locate the string to find, add something before and after it (which that something before and after could be different from each other), then continue the search to see if another instance exists. And so on and so forth....

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?

Thanks!

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



Reply via email to