Re: Using regex to replace text with bold version - problem with case

From: Date: Wed, 12 Jul 2000 21:18:20 +0000
Subject: Re: Using regex to replace text with bold version - problem with case
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-6278@lists.php.net to get a copy of this message
Andreas Pour <pour@mieterra.com> wrote: > Use: > > eregi_replace("($criteria)", "<b>\\1</b>", $txt); That did the trick, thanks. Thanks also to Chris Adams who offered the same solution off-list. For those searching the archives at a later date, I'll try to do a better job describing my problem. I have a web form that allows the user to input a keyword. My PHP script searches a MySQL database for documents containing the phrase and displays the results, which include a couple of lines of text from each document. If the keyword occurs in those two lines I wanted every occurence of the keyword to be enclosed in bold tags. But, I wanted the keyword and document text to be matched while ignoring the case of the text and I wanted the document text to retain its original case. I was using a combination of strtolower, strtoupper, and substr to convert the keyword to lowercase before using it in eregi_replace functions and looping through the document text searching for the keyword in lowercase, uppercase and with only the first letter in uppercase. That did not handle every possible combination of upper and lowercase and it wasn't very efficient. Steven Werby {steven-lists@befriend.com}

« previous php.general (#6278) next »