(PHP 5 >= 5.3.0, PHP 7, PHP 8, PECL intl >= 1.0.0)
grapheme_strstr — 從 haystack 字串中第一次出現 needle 的位置開始,返回 haystack 的一部分
程序式風格
從 haystack 字串中第一次出現 needle 的位置開始,返回 haystack 的一部分(包含 needle)。
haystack
輸入字串。必須是有效的 UTF-8。
needle
要搜尋的字串。必須是有效的 UTF-8。
beforeNeedle
如果為 true
,grapheme_strstr() 會返回 haystack
中第一次出現 needle
之前的部分(不包含 needle
)。
返回 haystack
的一部分,如果找不到 needle
則返回 false
。
範例 #1 grapheme_strstr() 範例
<?php
$char_a_ring_nfd = "a\xCC\x8A"; // 'LATIN SMALL LETTER A WITH RING ABOVE' (U+00E5) 正規化格式 "D"
$char_o_diaeresis_nfd = "o\xCC\x88"; // 'LATIN SMALL LETTER O WITH DIAERESIS' (U+00F6) 正規化格式 "D"
print urlencode(grapheme_stristr( $char_a_ring_nfd . $char_o_diaeresis_nfd . $char_a_ring_nfd, $char_o_diaeresis_nfd));
?>
以上範例會輸出
o%CC%88a%CC%8A