首页 电脑 电脑学堂 查看内容

PHP中strpos、strstr和stripos、stristr函数分析

2016-6-13 11:08 1701 0

摘要: 本文为大家分析了 PHP中strpos、strstr和stripos、stristr函数,供大家参考,具体内容如下strposmixed strpos ( string $haystack, mixed $needle )如果offset指定了,查找会从offset的位置开始。offset不能为负数 ...

本文为大家分析了 PHP中strpos、strstr和stripos、stristr函数,供大家参考,具体内容如下

strpos

mixed strpos ( string $haystack, mixed $needle [, int $offset = 0 ] )
如果offset指定了,查找会从offset的位置开始。offset不能为负数。

返回needle第一次出现在haystack的位置。如果在haystack中找不到needle,则返回FALSE。

needle,如果needle不是字符串,它会被转换成整型数值并赋值为该数值的ASCII字符。请看下面例子。

例子

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
$str = "hello";
$pos = strpos($str, 111);
// 111的ASCII值是o,因此$pos = 4
strpos核心源码
 
if (Z_TYPE_P(needle) == IS_STRING) {
   if (!Z_STRLEN_P(needle)) {
     php_error_docref(NULL TSRMLS_CC, E_WARNING, 声明:文章版权归原作者所有 部分文章转自互联网 如有侵权请联系 [邮箱地址] 删除

路过

雷人
1

握手

鲜花

鸡蛋

刚表态过的朋友 (1 人)

  • 握手

    匿名

最新评论