Having the same strings and diffrenet length

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tina_theod
Forum Newbie
Posts: 1
Joined: Sat Apr 03, 2010 3:23 pm

Having the same strings and diffrenet length

Post by tina_theod »

Hello I'm Tina.

I had an excel document with names of scientists and I put them in my database(MySQL).
I'm reading from .txt files other names and I'm searching to find if a name I have, there is already in my database.
I used the function strcmp() but it doesn't work in case that I have a name that already exists in my database.
Then I used the function strlen() and I discover that having the same name, the lengths of the same names are different!!!
For example,

From my database-> Theocharis, C. R. (String length1: 33)
From .txt files-> Theocharis, C. R. (String length2: 17)

The strcmp() function returns -1 but the names are same and it should return 0.
What I'm going to do??? :)
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Having the same strings and diffrenet length

Post by requinix »

The names aren't the same. They just look that way to you.

What if you give the database name to bin2hex and echo the result?
JakeJ
Forum Regular
Posts: 675
Joined: Thu Dec 10, 2009 6:27 pm

Re: Having the same strings and diffrenet length

Post by JakeJ »

It's possible that you have leading or trailing white space in your list as well. Extra spaces, tabs, etc. Use the trim() function.
Post Reply