* 1.strcmp($str1, $str2): Binary safe string comparison
* 2.strncmp($str1, $str2, $length): Compare whether the length specified at the beginning is the same
* 3.strcasecmp($str1, $str2): Binary safe string comparison, case-insensitive
* 4.strncasecmp($str1, $str2): Binary safe string comparison , case-insensitive
* 5.strspn($str,$mark,$start,$length): Get the length of the starting substring matching the mask
* 6. strcspn($str,$mark,$start,$length): Get the length of the starting substring of the unmatched mask
$str1 = 'php中文网'; $str2 = 'PHP中文网';
//1.strcmp($str1, $str2):String For comparison, return 0 if equal, return >0 if greater, otherwise return <0
echo strcmp($str1, $str2) == 0 ? '相等' : '不相等', '<br>';
//2.strncmp($str, $str2, $n): Compare whether the lengths specified at the beginning are equal
echo strncmp($str1, $str2, 3) == 0 ? '相等' : '不相等', '<br>';
//3.strcasecmp($str1, $str2): case-insensitive string comparison, returns 0 if equal, >0 if greater, otherwise returns <0
echo strcasecmp($str1, $str2) == 0 ? '相等' : '不相等', '<br>';
//4 .strncasecmp($str1, $str2): Case-insensitive comparison of whether the length specified at the beginning is equal
echo strncasecmp($str1, $str2,3) == 0 ? '相等' : '不相等', '<br>';
//5.strspn($str, $mark, $start, $length):
//Calculate the length of the first substring in which all characters in the string exist in the specified character set
//$str1: The string to be compared, $mark: Similar to a set, return Number of matches
echo strspn('15705519989', '1234567890'),'<br>'; //返回11
//You can specify the position and length to start comparison
echo strspn('15705519989', '1234567890', 4, 4),'<br>';//返回4
//Only compare the first substring in $str, ignore all the following ones, and return 11
echo strspn('15705519989 18955123344 111abc', '1234567890'),'<br>';
//Return 3, because only the first three in the first string are data belonging to the number set
echo strspn('157php 18955123344 111abc', '1234567890'),'<br>';
//For example, the mobile phone number must be a pure numeric string, requiring the user What must be entered is a purely numeric string
$phone = '13899886767';
// $phone = '1389988php6767';
$mark = '0123456789';
//Analysis, if it matches correctly, strspn() must return 11, because the phone The number is 11, which is exactly the same as strlen($phone)
echo strlen($phone)==strspn($phone, $mark) ? '全数字' : '必须全为数字';
//Equivalent to: strspn(substr($subject, $start, $length), $mask)
// 6. The functions of strcspn() and strspn() are exactly opposite. You can verify it by giving examples