stripos

stripos

(PHP 5)

stripos — 查找字符串首次出现的位置(不区分大小写)

说明

int stripos ( string $haystack , string $needle [, int $offset = 0 ] )

返回在字符串 haystack 中 needle 首次出现的数字位置。

与 strpos() 不同,stripos() 不区分大小写。

参数

haystack

在该字符串中查找。

needle

注意 needle 可以是一个单字符或者多字符的字符串。

如果 needle 不是一个字符串,那么它将被转换为整型并被视为字符顺序值。

offset

可选的 offset 参数允许你指定从 haystack 中的哪个字符开始查找。返回的位置数字值仍然相对于 haystack 的起始位置。

返回值

如果未发现 needle,stripos() 将返回布尔型 FALSE。

Warning

此函数可能返回布尔值 FALSE,但也可能返回等同于 FALSE 的非布尔值,例如 0 或 ""(空串)。请阅读 布尔类型章节以获取更多信息。应使用 === 运算符 来测试此函数的返回值。

范例

Example #1 stripos() 范例

<?php
$findme    
= 'a';
$mystring1 = 'xyz';
$mystring2 = 'ABC';

$pos1 = stripos($mystring1, $findme);
$pos2 = stripos($mystring2, $findme);

// 'a' 当然不在 'xyz' 中
if ($pos1 === false) {
    echo 
"The string '$findme' was not found in the string '$mystring1'";
}

// 注意这里使用的是 ===。简单的 == 不能像我们期望的那样工作,
// 因为 'a' 的位置是 0(第一个字符)。
if ($pos2 !== false) {
    echo 
"We found '$findme' in '$mystring2' at position $pos2";
}
?>

注释

Note: 此函数可安全用于二进制对象。

参见

  • strpos() - 查找字符串首次出现的位置
  • strrpos() - 计算指定字符串在目标字符串中最后一次出现的位置
  • strrchr() - 查找指定字符在字符串中的最后一次出现
  • substr() - 返回字符串的子串
  • stristr() - strstr 函数的忽略大小写版本
  • strstr() - 查找字符串的首次出现
  • strripos() - 计算指定字符串在目标字符串中最后一次出现的位置(不区分大小写)
  • str_ireplace() - str_replace 的忽略大小写版本

  • addcslashes
  • addslashes
  • bin2hex
  • chop
  • chr
  • chunk_split
  • convert_cyr_string
  • convert_uudecode
  • convert_uuencode
  • count_chars
  • crc32
  • crypt
  • echo
  • explode
  • fprintf
  • get_html_translation_table
  • hebrev
  • hebrevc
  • hex2bin
  • htmlentities
  • htmlspecialchars
  • htmlspecialchars_decode
  • html_entity_decode
  • implode
  • join
  • levenshtein
  • localeconv
  • ltrim
  • md5
  • md5_file
  • metaphone
  • money_format
  • nl2br
  • nl_langinfo
  • number_format
  • ord
  • parse_str
  • print
  • printf
  • quoted_printable_decode
  • quoted_printable_encode
  • quotemeta
  • rtrim
  • setlocale
  • sha1
  • sha1_file
  • similar_text
  • soundex
  • sprintf
  • sscanf
  • strcasecmp
  • strchr
  • strcmp
  • strcoll
  • strcspn
  • stripcslashes
  • stripos
  • stripslashes
  • strip_tags
  • stristr
  • strlen
  • strnatcasecmp
  • strnatcmp
  • strncasecmp
  • strncmp
  • strpbrk
  • strpos
  • strrchr
  • strrev
  • strripos
  • strrpos
  • strspn
  • strstr
  • strtok
  • strtolower
  • strtoupper
  • strtr
  • str_getcsv
  • str_ireplace
  • str_pad
  • str_repeat
  • str_replace
  • str_rot13
  • str_shuffle
  • str_split
  • str_word_count
  • substr
  • substr_compare
  • substr_count
  • substr_replace
  • trim
  • ucfirst
  • ucwords
  • vfprintf
  • vprintf
  • vsprintf
  • wordwrap
  • PHP MySQL HTML CSS JavaScript MSSQL AJAX .NET JSP Linux Mac ASP 服务器 SQL jQuery C# C++ java Android IOS oracle MongoDB SQLite wamp 交通频道