Table of contents Home page
setlocale(LC_ALL, 'sve_sve'); // Use the order of the Swedish alphabet // If the third argument is equal to or greater than the length of the longest string to be compared, this // function gives the same results as strcasecmp. $a = 'alpha'; $b = 'beta'; echo strncasecmp($a, $b, 5), "\n"; // 'alpha' sorts before 'beta' echo strncasecmp($b, $a, 5), "\n"; // 'beta' sorts after 'alpha' echo strncasecmp($a, $a, 5), "\n"; // 'alpha' == 'alpha' echo strncasecmp('Alpha', $a, 5), "\n"; // Case differences don't matter $a = 'mat'; $b = 'ål'; // In the Swedish alphabet 'm' sorts before 'å'! echo strncasecmp($a, $b, 3), "\n"; // 'mat' sorts before 'ål' echo strncasecmp($b, $a, 3), "\n"; // 'ål' sorts after 'mat') // And now we take into account just the first 3 characters, so the function should return 0 even though the two // strings are different. $a = 'abca'; $b = 'abcz'; echo strncasecmp($a, $b, 3), "\n";