二进制字符串的比较

1  strcmp — 二进制安全字符串比较

int strcmp  ( string $str1  , string $str2  )

 注意该比较区分大小写。

2  strcasecmp — 二进制安全比较字符串(不区分大小写)

int strcasecmp  ( string $str1  , string $str2  )

3 substr_compare — 二进制安全比较字符串(从偏移位置比较指定长度)

int substr_compare  ( string $main_str  , string $str  , int $offset  [, int $length  [, bool $case_insensitivity  = false  ]] )

substr_compare() 从偏移位置 offset 开始比较 main_strstr,比较长度为 length 个字符。 

<?php
 echo  substr_compare ( "abcde" ,  "bc" ,  1 ,  2 );  // 0
 echo  substr_compare ( "abcde" ,  "de" , - 2 ,  2 );  // 0
 echo  substr_compare ( "abcde" ,  "bcg" ,  1 ,  2 );  // 0
 echo  substr_compare ( "abcde" ,  "BC" ,  1 ,  2 ,  true );  // 0
 echo  substr_compare ( "abcde" ,  "bc" ,  1 ,  3 );  // 1
 echo  substr_compare ( "abcde" ,  "cd" ,  1 ,  2 );  // -1
 echo  substr_compare ( "abcde" ,  "abc" ,  5 ,  1 );  // warning
 ?> 

  

posted @ 2015-04-27 20:37  todaytoday  阅读(887)  评论(0编辑  收藏  举报