stripos()
是 PHP 中的一個字符串函數,它用于在字符串中查找一個子字符串,并返回其第一次出現的位置
<?php
$haystack = 'Hello, welcome to the world of PHP!';
$needle = 'PHP';
$position = stripos($haystack, $needle);
if ($position !== false) {
echo "The substring '{$needle}' is found at position {$position} in the string '{$haystack}'.";
} else {
echo "The substring '{$needle}' is not found in the string '{$haystack}'.";
}
?>
在這個示例中,我們在字符串 $haystack
中查找子字符串 $needle
(即 ‘PHP’)。stripos()
函數返回子字符串在源字符串中第一次出現的位置(從 0 開始計數)。如果子字符串不存在于源字符串中,則返回 false
。