By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,051 Members | 1,246 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,051 IT Pros & Developers. It's quick & easy.

Case sensitive comparisons with strcmp?

P: n/a
Hi :-)

I've written a mod for phpBB to give the forum admin more control over
the smilies. Part of the mod checks to make sure that no two smilies
have the same code.

code = :), :-), :D, :P, :lol:, :happy:, etc.

For some reason my mySQL code is finding a match between :D and :d, :P
and :p, :cool: and :COOL:, etc. Other than that it works fine.

$sql = "SELECT smilies_id FROM " . SMILIES_TABLE . " WHERE
smilies_id!='" . $smilies_id . "' AND code=STRCMP(code, '" .
addslashes($code) . "')";

I've just noticed that I can get around this (sort of) by comparing the
filenames as well, ie. :D and :d would be linked to the same smiley.
But I'd still like to know why STRCMP (which is case sensitive) is
finding a match between D and d. Any ideas?

Thanks.

Marc :O)
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Afkamm wrote:
For some reason my mySQL code is finding a match between :D and :d, :P
and :p, :cool: and :COOL:, etc. Other than that it works fine. [...] But I'd still like to know why STRCMP (which is case sensitive) is
finding a match between D and d. Any ideas?

<quote src="http://www.mysql.com/doc/en/String_comparison_functions.html">

As of MySQL 4.0, STRCMP() uses the current character set when performing
comparisons. This makes the default comparison behavior case insensitive
unless one or both of the operands are binary strings. Before MySQL 4.0,
STRCMP() is case sensitive.

</quote>
--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :
Jul 17 '05 #2

P: n/a
Drinkers log, beer date Fri, 02 Apr 2004 00:36:39 GMT. After downing
several pints in comp.lang.php, Pedro Graca slurred the following.
<quote
src="http://www.mysql.com/doc/en/String_comparison_functions.html">

As of MySQL 4.0, STRCMP() uses the current character set when
performing comparisons. This makes the default comparison behavior
case insensitive unless one or both of the operands are binary
strings. Before MySQL 4.0, STRCMP() is case sensitive.

</quote>

Thanks for that Pedro. :)
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.