欧美AV无码一区二区,麻豆+无码+国产在线+观看,欧美狂躁少妇XXXX高潮无码,美女扒开屁股让男人桶免费观看,极品粉嫩国产18尤物在线播放

strpos

(PHP 4, PHP 5, PHP 7, PHP 8)

strpos查找字符串首次出現的位置

說(shuō)明

strpos(string $haystack, mixed $needle, int $offset = 0): int

返回 needlehaystack 中首次出現的數字位置。

參數

haystack

在該字符串中進(jìn)行查找。

needle

Prior to PHP 8.0.0, if needle is not a string, it is converted to an integer and applied as the ordinal value of a character. This behavior is deprecated as of PHP 7.3.0, and relying on it is highly discouraged. Depending on the intended behavior, the needle should either be explicitly cast to string, or an explicit call to chr() should be performed.

offset

如果提供了此參數,搜索會(huì )從字符串該字符數的起始位置開(kāi)始統計。 如果是負數,搜索會(huì )從字符串結尾指定字符數開(kāi)始。

返回值

返回 needle 存在于 haystack 字符串起始的位置(獨立于 offset)。同時(shí)注意字符串位置是從0開(kāi)始,而不是從1開(kāi)始的。

如果沒(méi)找到 needle,將返回 false。

警告

此函數可能返回布爾值 false,但也可能返回等同于 false 的非布爾值。請閱讀 布爾類(lèi)型章節以獲取更多信息。應使用 === 運算符來(lái)測試此函數的返回值。

更新日志

版本 說(shuō)明
7.1.0 開(kāi)始支持負數的 offset。

范例

示例 #1 使用 ===

<?php
$mystring 
'abc';
$findme   'a';
$pos strpos($mystring$findme);

// 注意這里使用的是 ===。簡(jiǎn)單的 == 不能像我們期待的那樣工作,
// 因為 'a' 是第 0 位置上的(第一個(gè))字符。
if ($pos === false) {
    echo 
"The string '$findme' was not found in the string '$mystring'";
} else {
    echo 
"The string '$findme' was found in the string '$mystring'";
    echo 
" and exists at position $pos";
}
?>

示例 #2 使用 !==

<?php
$mystring 
'abc';
$findme   'a';
$pos strpos($mystring$findme);

// 使用 !== 操作符。使用 != 不能像我們期待的那樣工作,
// 因為 'a' 的位置是 0。語(yǔ)句 (0 != false) 的結果是 false。
if ($pos !== false) {
     echo 
"The string '$findme' was found in the string '$mystring'";
         echo 
" and exists at position $pos";
} else {
     echo 
"The string '$findme' was not found in the string '$mystring'";
}
?>

示例 #3 使用位置偏移量

<?php
// 忽視位置偏移量之前的字符進(jìn)行查找
$newstring 'abcdef abcdef';
$pos strpos($newstring'a'1); // $pos = 7, 不是 0
?>

注釋

注意: 此函數可安全用于二進(jìn)制對象。

參見(jiàn)

  • stripos() - 查找字符串首次出現的位置(不區分大小寫(xiě))
  • strrpos() - 計算指定字符串在目標字符串中最后一次出現的位置
  • strripos() - 計算指定字符串在目標字符串中最后一次出現的位置(不區分大小寫(xiě))
  • strstr() - 查找字符串的首次出現
  • strpbrk() - 在字符串中查找一組字符的任何一個(gè)字符
  • substr() - 返回字符串的子串
  • preg_match() - 執行匹配正則表達式

欧美AV无码一区二区,麻豆+无码+国产在线+观看,欧美狂躁少妇XXXX高潮无码,美女扒开屁股让男人桶免费观看,极品粉嫩国产18尤物在线播放