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 strcmp. $a = 'alpha'; $b = 'beta'; echo strncmp($a, $b, 5), "\n"; // 'alpha' sorts before 'beta' echo strncmp($b, $a, 5), "\n"; // 'beta' sorts after 'alpha' echo strncmp($a, $a, 5), "\n"; // 'alpha' == 'alpha' echo strncmp('Alpha', $a, 5), "\n"; // 'Alpha' sorts before 'alpha' $a = 'mat'; $b = 'ål'; // In the Swedish alphabet 'm' sorts before 'å'! echo strncmp($a, $b, 3), "\n"; // 'mat' sorts before 'ål' echo strncmp($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 strncmp($a, $b, 3), "\n";