PHP string comparison with '<' or '>' operators <?php $string1 = 'abc'; $string2 = 'abcd'; if ($string1 > $string2) { echo 'true'; } else { echo 'false'; } ?> #output: false How to compare strings case insensitive in PHP?
int strcasecmp ( string $str1 , string $str2 ) This means thatstrcasecmp()function accepts two string (comma separated) as input to compare and returns an int (integer). See the following table to understand the above function definition in an easy way: ...
, here is a compare function that compares strings by the case-insensitive method, unless it finds a grade, in which case it correctly sorts by putting "plus" grades first, unmarked grades second, and "minus" grades last. <?php function cmp($a, $b) { $a = preg_replace('@^(a|an...
If the two strings has the same 1st character, then compare the 2nd character and so on. 1 2 3 4 5 6 <?PHP $diff=strcmp("jhb","jha"); echo "$diff"; //1 $diff=strcmp("jha","jhb"); echo "$diff"; //-1 ?> If the 1st string and the 2nd string has the same first ...
示例#1 strncasecmp() 示例 <?php$var1 = 'Hello John';$var2 = 'hello Doe';if (strncasecmp($var1, $var2, 5) === 0) { echo 'First 5 characters of $var1 and $var2 are equals in a case-insensitive string comparison';}?>参见...
$string2 ="Good health Good life."; $case_insensitivity =FALSE;// here, this function works as case-insensitiveechosubstr_compare($main_str, $string2,0,9,TRUE)."";// here, this function case-sensitiveechosubstr_compare($main_str,"GOOD Health",0,11, $case_insensitivity)."";//the fu...
strstr — Find first occurrence of a string strtok — Tokenize string strtolower — Make a string lowercase strtoupper — Make a string uppercase strtr — Translate certain characters substr_compare — Binary safe optionally case insensitive comparison of 2 strings from an offset, up to length char...
Case-insensitive version of str_replace(). str_pad() Pad a string to a certain length with another string. str_repeat() Repeats a string a specified number of times. str_replace() Replace all occurrences of the search string with the replacement string (case-sensitive). str_rot13() ...
Quote string with slashes 使用反斜线引用字符串 bin2hex() Convert binary data into hexadecimal representation 函数把包含数据的二进制字符串转换为十六进制值 chop() Alias of rtrim rtrim 的别名 chr() Return a specific character 返回指定的字符
>0 - if string1 is greater than string2 PHP Version:4+ More Examples Example Compare two strings (case-insensitive = HELLO and hELLo will output the same): <?php echostrcasecmp("Hello","HELLO"); echo""; echostrcasecmp("Hello","hELLo"); ?> Try...