Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Comparing Strings- Problems with differently encoded spaces

Status
Not open for further replies.

groovygarden

Programmer
Aug 23, 2001
63
0
0
Hiya,

I'm trying to compare two strings. One is an array, $list, generated from a select statement, the other is a value, $selected, which holds the value a user has chosen from a <select> drop down.

$list[$i]==$selected

Problem is, even when the strings should match, they don't.
The strings are exactly the same, except that spaces in the string are encoded differently. Someone helpfully suggested I use the ord function and it turns out that in $selected spaces are encoded with 160 where as in $list the code is 32.

Am I right in thinking this is why the strings don't match even though they echo the &quot;same&quot;. What can I do to change the way spaces are encoded or can anyone think of a way round this?

Any suggestions much appreciated

Thanks
 
use a search and replace function:

str_replace(chr(32), chr(160), $list[$i]);

that will convert all the &quot;32&quot; spaces into 160's so you should be able to compare them properly
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top