(PHP 5 >= 5.3.0,PHP 7,PHP 8,PECL intl >= 1.0.0)
grapheme_strpos — 尋找字串首次出現的位置(以字形為單位)
haystack (搜尋的字串)
要在其中搜尋的字串。必須是有效的 UTF-8 編碼。
needle(待搜尋字串)
要搜尋的字串。必須是有效的 UTF-8 編碼。
offset(偏移量)
選用的 offset
參數允許您指定在 haystack
中開始搜尋的位置,以字素單位(非位元組或字元)表示的偏移量。如果偏移量為負數,則它會被視為相對於字串結尾。無論 offset
的值為何,返回的位置仍然是相對於 haystack
的開頭。
返回位置的整數值。如果找不到 needle
,grapheme_strpos() 將返回 false
。
版本 | 說明 |
---|---|
7.1.0 | 已新增支援負數 offset 。 |
範例 #1 grapheme_strpos() 範例
<?php
$char_a_ring_nfd = "a\xCC\x8A"; // '帶上環的小寫拉丁字母 A' (U+00E5) 正規化格式 "D"
$char_o_diaeresis_nfd = "o\xCC\x88"; // '帶分音符的小寫拉丁字母 O' (U+00F6) 正規化格式 "D"
print grapheme_strpos( $char_a_ring_nfd . $char_a_ring_nfd . $char_o_diaeresis_nfd, $char_o_diaeresis_nfd);
?>
以上範例將輸出
2