Forum Moderators: coopster & phranque

Message Too Old, No Replies

Help with searching .txt file

want to do a case insensitive search

         

IamStang

7:59 pm on Feb 26, 2005 (gmt 0)

10+ Year Member



Hi all,

First time poster at this board.

I have a file userhomes.txt (not actual name) that contains user ID's and their homepages set up like:


uSer001多ttp://www.user001homepage.com
USer002多ttp://www.user001homepage.com
useR003多ttp://www.user001homepage.com
usEr004多ttp://www.user001homepage.com
User005多ttp://www.user001homepage.com

Notice that the user names contain upper and lower case letters. If they were all lower case, the answer to my question would be fairly easy.

But, as they are not all lower case, how can I return the correct information if the visitor types USER001 into a search field?

I know that I could edit the text file and change all user names to lowercase. But, if I can help it, I would rather not. There is another script that uses this file and the names have to match their login.

I think what I need the script to do is convert the input from the form into lower case letters, load the data from the txt file, convert the data to lower case and then do a comparison. Is this possible? If it is, could someone point me to a tutorial/example of this?

Any and all help is appreciated!

Moby_Dim

7:39 am on Feb 27, 2005 (gmt 0)

10+ Year Member



Have you heard of 'i' modifier?

Matt Probert

10:56 am on Feb 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



But, as they are not all lower case, how can I return the correct information if the visitor types USER001 into a search field?

if ($search_name =~ /$text_record/i)
{
.....
}

As previously mentioned, the 'i' modifier does a case insensitive comparison.

Matt

IamStang

1:16 pm on Feb 27, 2005 (gmt 0)

10+ Year Member



Well, as a matter of fact, at about midnight last night, I DID hear of the "i" modifier. And I managed to get my search working.

Thanks Matt!

Would also have said thanks to you Moby, if your reply did not sound so sarcastic. There ARE some people in the world that are just starting to learn cgi. Just thought I would clue you in to that. I missed the part in the agreement where it stated you need to be a guru to post here. Sorry I bothered to post at this board. I will go elsewhere for any further questions I might have.

Moby_Dim

2:01 pm on Feb 27, 2005 (gmt 0)

10+ Year Member



Sorry, IamStang, I think this's because of my English language problems. I did not want to scare you. Sorry again. As for the short answer without a detailed instructions, I've made this because of own experience: it's better to give a hint as an impulse, a pointer in the right direction to do the next yourself. And if you obtain the full answer, it's possible the core problem remains the same - unclear. 3-rd sorry in the end.

rocknbil

5:59 pm on Feb 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yeah, and it helps not to be so thin skinned, in a few years you'll understand how some posters grow weary of the repetitive questions that are answered elsewhere. Anyway, glad you got your answer and welcome aboard!

coopster

6:17 pm on Feb 28, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, IamStang.

Hopefully you come back and see that you are indeed quite welcome here. Thanks for posting :)