當前位置: 首頁> 函數類別大全> strncmp

strncmp

二進制安全比較字符串開頭的若干個字符
名稱:strncmp
分類:字符串
所屬語言:php
一句話介紹:前n 個字符的字符串比較(對大小寫敏感)。

實例

例子1

比較兩個字符串(區分大小寫):

 <span class="token php language-php"><span class="token delimiter important"><?php</span>
<span class="token keyword">echo</span> <span class="token function">strncmp</span> <span class="token punctuation">(</span> <span class="token string double-quoted-string">"I love China!"</span> <span class="token punctuation">,</span> <span class="token string double-quoted-string">"I love Shanghai!"</span> <span class="token punctuation">,</span> <span class="token number">6</span> <span class="token punctuation">)</span> <span class="token punctuation">;</span>
<span class="token delimiter important">?></span></span>

親自試一試

例子2

比較兩個字符串(區分大小寫,China 和CHINA 輸出不相同):

 <span class="token php language-php"><span class="token delimiter important"><?php</span>
<span class="token keyword">echo</span> <span class="token function">strncmp</span> <span class="token punctuation">(</span> <span class="token string double-quoted-string">"China"</span> <span class="token punctuation">,</span> <span class="token string double-quoted-string">"China"</span> <span class="token punctuation">,</span> <span class="token number">6</span> <span class="token punctuation">)</span> <span class="token punctuation">;</span>
<span class="token keyword">echo</span> <span class="token string double-quoted-string">"<br>"</span> <span class="token punctuation">;</span>
<span class="token keyword">echo</span> <span class="token function">strncmp</span> <span class="token punctuation">(</span> <span class="token string double-quoted-string">"China"</span> <span class="token punctuation">,</span> <span class="token string double-quoted-string">"CHINA"</span> <span class="token punctuation">,</span> <span class="token number">6</span> <span class="token punctuation">)</span> <span class="token punctuation">;</span>
<span class="token delimiter important">?></span></span>

親自試一試

同類函數
  • 計算字符串中全部字符都存在於指定字符集合中的第一段子串的長度 strspn

    strspn

    計算字符串中全部字符都存在於指定字符集合
  • 二進制安全不區分大小寫的字符串比較 strcasecmp

    strcasecmp

    二進制安全不區分大小寫的字符串比較
  • 反引用一個使用addcslashes() 轉義的字符串 stripcslashes

    stripcslashes

    反引用一個使用addcslashes()
  • 查找指定字符在字符串中的最後一次出現 strrchr

    strrchr

    查找指定字符在字符串中的最後一次出現
  • 計算指定字符串在目標字符串中最後一次出現的位置(不區分大小寫) strripos

    strripos

    計算指定字符串在目標字符串中最後一次出現
  • 將一個一維數組的值轉化為字符串 implode

    implode

    將一個一維數組的值轉化為字符串
  • 將字符串轉化為小寫 strtolower

    strtolower

    將字符串轉化為小寫
  • 返回格式化的字符串 vsprintf

    vsprintf

    返回格式化的字符串