You don't need regular expressions for this.

To match case insensitive, just upper or lower case both strings
and use strpos() to find an occurence. Now you allready have the
position of the match it'll be easy to get that part of the string.

I suggest you substr() it into 3 parts and put the <B> and </B> in between.


On Tue, 26 Feb 2002 11:50:31 +0200 (EET), Kristjan Kanarik wrote:

>I've never had time to get into those ereg, eregi etc. functions, and now
>I am affraid I probably need to use them. Here is the problem I need to
>I have a string (lead of an article), about 200-250 characters long. And
>then I do have a search query - variable $q
>Now, what I'd like to do is to check wheter this string contains the
>search query or not. Case sensitivity is not important, so if the $q
>equals to 'SoMeThInG', the script would find also 'sOmEtHiNg'. If the
>string contains the search query, I'd like to display 100 characters of
>this string (lead) - the search query should be in the middle of this
>substring and within BOLD and /BOLD tags.
>If the search query is in the beginning of the string, say at position 10,
>then I'd like to display 100 first characters of the string... and if it
>is say at position 230 (250 chars together), it should display the string
>starting at position 250-100.
>I know it shouldn't be difficult to do, but I am kind of stuck and
>P.S. Pls. CC me as well - I am only in the digest.
>PHP General Mailing List (
>To unsubscribe, visit:

PHP General Mailing List (
To unsubscribe, visit:

Reply via email to