PHP 字符串 strncmp() 函數(shù)
strncmp() 是 PHP 的預(yù)定義字符串函數(shù)。愛掏網(wǎng) - it200.com它用于比較兩個(gè)字符串。愛掏網(wǎng) - it200.com這個(gè)函數(shù) strncmp() 是二進(jìn)制安全的、區(qū)分大小寫的,與 strcmp() 函數(shù)類似,但 strcmp() 函數(shù)沒有長度參數(shù)。愛掏網(wǎng) - it200.com
strncmp() 函數(shù)在編程和Web開發(fā)中經(jīng)常用于字符串操作。愛掏網(wǎng) - it200.com
strncmp(string1,string2,length);
參數(shù) | 描述 | 必需/可選 |
---|---|---|
String1 | 指定要比較的第一個(gè)字符串 | 必需 |
String2 | 指定要比較的第二個(gè)字符串 | 必需 |
Length | 指定要比較的字符數(shù) | 必需 |
strncmp()函數(shù):
- 返回0:如果兩個(gè)字符串相等。愛掏網(wǎng) - it200.com
- 返回<0:如果字符串1小于字符串2。愛掏網(wǎng) - it200.com
- 返回>0:如果字符串1大于字符串2。愛掏網(wǎng) - it200.com
示例1
<?php
str1 = "PHP javatpoint";str2 = "PHP javatpoint";
echo "By using 'strcmp()' function:".strcmp(str1,str2);
// it will return: 0 ( Both string is equall )
?>
輸出:
By using 'strcmp()' function: 0
示例2
<?php
str1 = "PHP javatpoint";str2 = "PHP javatpoint tutorial";
echo "By using 'strcmp()' function:".strcmp(str1,str2);
// it will return: -9 ( str2 is greater than str1)
?>
輸出:
By using 'strcmp()' function:-9
示例3
<?php
str1 = "PHP javatpoint tutorial";str2 = "PHP javatpoint";
echo "By using 'strcmp()' function:".strcmp(str1,str2);
// it will return: 9 ( str1 is greater than str2)
?>
輸出:
By using 'strcmp()' function:9
參見
- str_word_count():用于計(jì)算字符串中的單詞數(shù)量。愛掏網(wǎng) - it200.com
- strcasecmp():用于比較兩個(gè)字符串。愛掏網(wǎng) - it200.com
- strchr():用于在一個(gè)字符串中查找另一個(gè)字符串的第一次出現(xiàn)。愛掏網(wǎng) - it200.com
參考:
http://php.net/manual/en/function.strncmp.php
聲明:所有內(nèi)容來自互聯(lián)網(wǎng)搜索結(jié)果,不保證100%準(zhǔn)確性,僅供參考。如若本站內(nèi)容侵犯了原著者的合法權(quán)益,可聯(lián)系我們進(jìn)行處理。