strpos

说明

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

返回 needle haystack 中首次出现的数字位置。该函数可以使用一个完整字符串作为 needle ,并且整个字符串都将被使用。

参数

 

haystack

在该字符串中进行查找。

needle

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

offset

可选的 offset 参数可以用来指定从 haystack 中的哪一个字符开始查找。返回的数字位置是相对于 haystack 的起始位置而言的。

 

返回值

以整型返回位置信息。如果没找到 needle strpos() 将返回 布尔型 的 FALSE 值。

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

// 注意这里使用的是 ===。简单的 == 不能像我们期待的那样工作,
// 因为 'a' 是第 0 位置上的(第一个)字符。
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 " ;
}
?> 
<?php
$mystring  =  'abc' ;
$findme    =  'a' ;
$pos  =  strpos ( $mystring ,  $findme );

// 使用 !== 操作符。使用 != 不能像我们期待的那样工作,
// 因为 'a' 的位置是 0。语句 (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 '" ;
}
?> 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值