Strict
Not using strict operator === can lead to variable type problems.
$string = "123abc";
echo $string == 123 ? 'true' : 'false';
echo $string === 123 ? 'true' : 'false';
Safe
Binary
safe string comparison.
Returns < 0 if str1 is less than str2
Returns > 0 if str1 is greater than str2
Returns 0 if they are equal
echo strcmp("a", "a");
echo strcasecmp("A", "a");
echo strcmp("A", "a");
echo strcmp("a", "A");
Binary safe string comparison (n characters)
$str = "hello John";
echo strncasecmp($str, "Hello World", 5);
substr_compare()
echo substr_compare("abcde", "bc", 1, 2);
echo substr_compare("abcde", "de", -2, 2);
echo substr_compare("abcde", "cd", 1, 2);
echo substr_compare("abcde", "bc", 1, 3);
echo substr_compare("abcde", "BC", 1, 2, true);
echo substr_compare("abcde", "abc", 5, 1);
Similar
similar_text() returns the
number of matching chars in both strings.
echo similar_text("cat", "can");
similar_text("cat", "can", $percent);
echo $percent;
Levenshtein
Minimal number of characters you have to replace.
Insert or delete
to transform str1 into str2.
echo levenshtein('cat', 'can');
Soundex
Words pronounced similarly produce the same soundex key.
Can be used to simplify
searches in databases.
echo soundex('wise');
echo soundex('ways');