0

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?

Giorgio
  • 1,940
  • 5
  • 39
  • 64
  • 2
    Check the ASCII table: space (0x20) < `T` (0x54) < `\`` (0x60). The sorting is correct according to `strcmp`. – Progman Nov 08 '20 at 10:52

1 Answers1

1

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

Back2Lobby
  • 534
  • 6
  • 12