Giorgio
Giorgio

Reputation: 1970

Unexpected strcmp behaviour with strings containing backticks

I'm facing a strange problem with the strcmp function. I need to compare 2 strings containing the backtick character (`):

$result = strcmp('CREATE TABLE `postsTranslations` (', 'CREATE TABLE `posts` (');

I expected that the result of this comparison should be >0 since postsTranslations is alphabetically after posts. But the result is -1. If I remove the backticks, everything works as expected. Would it be possible to alphabetically compare these strings without removing backticks?

Upvotes: 0

Views: 122

Answers (1)

Back2Lobby
Back2Lobby

Reputation: 593

You need to use strcasecmp here. It does the binary safe case-insensitive string comparison.

Upvotes: 1

Related Questions