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

strspn

計算字符串中全部字符都存在於指定字符集合中的第一段子串的長度
名稱:strspn
分類:字符串
所屬語言:php
一句話介紹:返回在字符串中包含的特定字符的數目。

實例

例子1

返回在字符串"Hello world!" 中包含字符"kHlleo" 的數目:

 <span class="token php language-php"><span class="token delimiter important"><?php</span>
<span class="token keyword">echo</span> <span class="token function">strspn</span> <span class="token punctuation">(</span> <span class="token string double-quoted-string">"Hello world!"</span> <span class="token punctuation">,</span> <span class="token string double-quoted-string">"kHlleo"</span> <span class="token punctuation">)</span> <span class="token punctuation">;</span>
<span class="token delimiter important">?></span></span>

親自試一試

例子2

返回在字符串"abcdefand" 中包含字符"abc" 的數目:

 <span class="token php language-php"><span class="token delimiter important"><?php</span>
<span class="token keyword">echo</span> <span class="token function">strspn</span> <span class="token punctuation">(</span> <span class="token string double-quoted-string">"abcdefand"</span> <span class="token punctuation">,</span> <span class="token string double-quoted-string">"abc"</span> <span class="token punctuation">)</span> <span class="token punctuation">;</span>
<span class="token delimiter important">?></span></span>

親自試一試

同類函數
  • 反轉一個字符串 strrev

    strrev

    反轉一個字符串
  • 不區分大小寫的strstr stristr

    stristr

    不區分大小寫的strstr
  • 重複一個字符串 str_repeat

    str_repeat

    重複一個字符串
  • 計算指定字符串在目標字符串中最後一次出現的位置 strrpos

    strrpos

    計算指定字符串在目標字符串中最後一次出現
  • 將字符串拆分為較小的塊 chunk_split

    chunk_split

    將字符串拆分為較小的塊
  • 子字符串替換 str_replace

    str_replace

    子字符串替換
  • 根據指定格式解析輸入的字符 sscanf

    sscanf

    根據指定格式解析輸入的字符
  • 刪除字符串末端的空白字符(或者其他字符) rtrim

    rtrim

    刪除字符串末端的空白字符(或者其他字符)
熱門文章