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

strpbrk

在字符串中查找一組字符的任何一個字符-返回一個以找到的字符開始的子字符串
名稱:strpbrk
分類:字符串
所屬語言:php
一句話介紹:在字符串中查找一組字符的任何一個字符。

實例

例子1

在字符串中搜索字符"Sh",並返回字符串中從指定字符第一次出現的位置開始的剩餘部分:

 <span class="token php language-php"><span class="token delimiter important"><?php</span>
<span class="token keyword">echo</span> <span class="token function">strpbrk</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 string double-quoted-string">"Sh"</span> <span class="token punctuation">)</span> <span class="token punctuation">;</span>
<span class="token delimiter important">?></span></span>

親自試一試

例子2

該函數區分大小寫("S" 和"s" 輸出不相同):

 <span class="token php language-php"><span class="token delimiter important"><?php</span>
<span class="token keyword">echo</span> <span class="token function">strpbrk</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 string double-quoted-string">"S"</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">strpbrk</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 string double-quoted-string">"s"</span> <span class="token punctuation">)</span> <span class="token punctuation">;</span>
<span class="token delimiter important">?></span></span>

親自試一試

同類函數
  • 計算子字符串出現次數 substr_count

    substr_count

    計算子字符串出現次數
  • 二進制安全字符串比較 strcmp

    strcmp

    二進制安全字符串比較
  • 將一個一維數組的值轉化為字符串 implode

    implode

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

    strrpos

    計算指定字符串在目標字符串中最後一次出現
  • 將字符串的第一個字符設為小寫 lcfirst

    lcfirst

    將字符串的第一個字符設為小寫
  • strstr的別名 strchr

    strchr

    strstr的別名
  • 二進制安全不區分大小寫的字符串比較 strcasecmp

    strcasecmp

    二進制安全不區分大小寫的字符串比較
  • 將8位字符串轉換為帶引號的可打印字符串 quoted_printable_encode

    quoted_printable_encode

    將8位字符串轉換為帶引號的可打印字符串
熱門文章