php -- strpos,stripos,strrpos,strripos,strstr,strchr,stristr,strrchr
strpos() 函数
语法:
mixed strpos ( string $haystack
, mixed $needle
[, int $offset
= 0 ] )
查找 needle
在 haystack
中第一次出现的位置。大小写敏感。
如果成功,则返回位置,否则返回 false。
正则:/ /i ,有i,表示不区分大小写,同样,这里类似:没有i表示区分大小写,有i表示不区分大小写
参数:
haystack:
在该字符串中进行查找。
needle:
如果 needle
不是一个字符串,那么它将被转换为整型并被视为字符的顺序值。
offset:
如果提供了此参数,搜索会从字符串该字符数的起始位置开始统计。和 strrpos()、 strripos()不一样,这个偏移量不能是负数。
$mystring = 'helloworld'; $findme = 'l';
$pos = strpos($mystring, $findme); //$pos值为2 $findme = 'L';
$pos = strpos($mystring, $findme); //$pos值为false $findme = 'q';
$pos = strpos($mystring, $findme); //$pos值为false
stripos
语法:
mixed strpos ( string $haystack
, mixed $needle
[, int $offset
= 0 ] )
查找 needle
在 haystack
中第一次出现的位置。大小写不敏感。
如果成功,则返回位置,否则返回 false。
正则:/ /i ,有i,表示不区分大小写,同样,这里类似:没有i表示区分大小写,有i表示不区分大小写
参数:
haystack:
在该字符串中查找。
needle:
注意 needle
可以是一个单字符或者多字符的字符串。如果 needle
不是一个字符串,那么它将被转换为整型并被视为字符顺序值。
offset:
可选的 offset
参数允许你指定从 haystack
中的哪个字符开始查找。返回的位置数字值仍然相对于haystack
的起始位置。
$mystring = 'helloworld'; $findme = 'l';
$pos = stripos($mystring, $findme); //$pos值为2 $findme = 'L';
$pos = stripos($mystring, $findme); //$pos值为2 $findme = 'q';
$pos = stripos($mystring, $findme); //$pos值为false
*******************************************************************************************************************
strrpos() 函数
语法
mixed strrpos ( string $haystack
, string $needle
[, int $offset
= 0 ] )
查找 needle
在 haystack
中最后一次出现的位置。大小写敏感。
如果成功,则返回位置,否则返回 false。
正则:/ /i ,有i,表示不区分大小写,同样,这里类似:没有i表示区分大小写,有i表示不区分大小写
参数
haystack:
在此字符串中进行查找。
needle:
注意 needle
可以是一个单字符或者多字符的字符串。
offset:或许会查找字符串中任意长度的子字符串。负数值将导致查找在字符串结尾处开始的计数位置处结束。
$mystring = 'helloworld'; $findme = 'l';
$pos = strrpos($mystring, $findme); //$pos值为8 $findme = 'L';
$pos = strrpos($mystring, $findme); //$pos值为false $findme = 'q';
$pos = strrpos($mystring, $findme); //$pos值为false
strripos() 函数
语法
mixed strripos ( string $haystack
, string $needle
[, int $offset
= 0 ] )
查找 needle
字符串在 haystack
中最后一次出现的位置。大小写不敏感。
如果成功,则返回位置,否则返回 false。
正则:/ /i ,有i,表示不区分大小写,同样,这里类似:没有i表示区分大小写,有i表示不区分大小写
参数
haystack:
在此字符串中进行查找。
needle:
注意 needle
可以是一个单字符或者多字符的字符串。
offset:
参数 offset
可以被指定来查找字符串中任意长度的子字符串。负数偏移量将使得查找从字符串的起始位置开始,到 offset
位置为止。
$mystring = 'helloworld'; $findme = 'l';
$pos = strripos($mystring, $findme); //$pos值为8 $findme = 'L';
$pos = strripos($mystring, $findme); //$pos值为8 $findme = 'q';
$pos = strripos($mystring, $findme); //$pos值为false
*******************************************************************************************************************
strstr () 函数(strchr)
语法
string strstr ( string $haystack
, mixed $needle
[, bool $before_needle
= false ] )
返回 needle 在
第一次出现的位置开始到结尾的字符串。大小写敏感。haystack
中
如果成功,则返回字符串,否则返回 false。
正则:/ /i ,有i,表示不区分大小写,同样,这里类似:没有i表示区分大小写,有i表示不区分大小写
参数
haystack:
输入字符串。
needle:
如果 needle
不是一个字符串,那么它将被转化为整型并且作为字符的序号来使用。
before_needle:
若为 TRUE
,strstr() 将返回 needle
在 haystack
中的位置之前的部分。
$mystring = 'helloworld'; $findme = 'l';
$pos = strstr($mystring, $findme); //$pos值为lloworld $findme = 'L';
$pos = strstr($mystring, $findme); //$pos值为false $findme = 'q';
$pos = strstr($mystring, $findme); //$pos值为false
stristr () 函数
语法
string stristr ( string $haystack
, mixed $needle
[, bool $before_needle
= false ] )
返回 needle 在
最后一次出现的位置到结尾的字符串。大小写不敏感。haystack
中
如果成功,则返回字符串,否则返回 false。
正则:/ /i ,有i,表示不区分大小写,同样,这里类似:没有i表示区分大小写,有i表示不区分大小写
参数
haystack:
在该字符串中查找。
needle:
如果 needle
不是一个字符串,那么它将被转换为整型并被视为字符顺序值。
before_needle:
若为 TRUE
,strstr() 将返回 needle
在 haystack
中的位置之前的部分(不包括 needle)。
$mystring = 'helloworld'; $findme = 'l';
$pos = stristr($mystring, $findme); //$pos值为lloworld $findme = 'L';
$pos = stristr($mystring, $findme); //$pos值为lloworld $findme = 'q';
$pos = stristr($mystring, $findme); //$pos值为false
*******************************************************************************************************************
strrchr() 函数
语法
string strrchr ( string $haystack
, mixed $needle
)
返回 haystack
字符串中的一部分,这部分以 needle
的最后出现位置开始,直到 haystack
末尾。
如果成功,则返回字符串,否则返回 false。
正则:/ /i ,有i,表示不区分大小写,同样,这里类似:没有i表示区分大小写,有i表示不区分大小写
参数
haystack:
在此字符串中进行查找。
needle:
注意 needle
可以是一个单字符或者多字符的字符串。
offset:
参数 offset
可以被指定来查找字符串中任意长度的子字符串。负数偏移量将使得查找从字符串的起始位置开始,到 offset
位置为止。
$mystring = 'helloworld'; $findme = 'l';
$pos = strrchr($mystring, $findme); //$pos值为ld $findme = 'L';
$pos = strstr($mystring, $findme); //$pos值为false $findme = 'q';
$pos = strstr($mystring, $findme); //$pos值为false
strrichr()函数 -- 没有
********************************************************************************************************************
php -- strpos,stripos,strrpos,strripos,strstr,strchr,stristr,strrchr的更多相关文章
- [PHP] strpos stripos strrpos strripos的区别
stripos — 查找字符串首次出现的位置(不区分大小写),应使用 === 运算符来测试此函数的返回值 strpos 左边开始字符出现的第一个位置,区分大小写stripos 和上面一样,不区分大小写 ...
- PHP字符串函数之 strpos stripos strrpos strripos
strpos – 查找字符串首次出现的位置 stripos – 查找字符串首次出现的位置(不区分大小写) strrpos – 计算指定字符串在目标字符串中最后一次出现的位置 strripos – 计算 ...
- php strpos(), stripos(),strrpos(), strripos()的区别
strpos(), 左边开始,字符出现第一个位置,区分大小写: stripos(),不区分大小写: strrpos(), 左边开始,字符出现,最后一个位置,区分大小写: strripos()不区分大小 ...
- php中strstr、strchr、strrchr、substr、stristr
一.strstr 和 strcchr的区别 strstr 显示第一次找到,要查找的字符串,以及后面的字符串. strrchr 显示最后一次找到,要查找的字符串,以及后面的字符串. 二.strstr ...
- php使用strpos,strstr,strchr注意啦,若是数字查找则会当成ASCII码处理
strpos,strstr,strchr都是查找某字符出现的位置,若未找到,则返回false(判断是===) 如: var_dump(strpos("oa",'97')); var ...
- PHP stripos()、strripos()和strrpos() 使用方法和区别
区别 stripos():查找字符串首次出现的位置(不区分大小写) 写法:stripos ( string $haystack , string $needle [, int $offset = 0 ...
- 内存及字符串操作篇strlen strchar strcmp strcoll strcpy strdup strstr strtok strspn strrchr bcmp bcopy bzero index memccpy memset
bcmp(比较内存内容) 相关函数 bcmp,strcasecmp,strcmp,strcoll,strncmp,strncasecmp 表头文件 #include<string.h> 定 ...
- c常用函数-strchr和strrchr
strchr和strrchr strrchr函数用于查找指定字符在一个字符串中最后一次出现的位置,然后返回指向该位置的指针 strchr函数用于查找指定字符在一个字符串中第一次出现的位置,然后返回指向 ...
- strstr()查找函数,strchr(),strrchr(),stristr()/strpos(),strrpos()查找字符串位置
在一个较长的字符串这查找匹配的字符串或字符,其中strstr()和strchr()是完全一样的. 例: echo strstr('why always you','you'); 输出: you 如果为 ...
随机推荐
- linux cut 命令
cut:以某种方式按照文件的行进行分割 参数列表: -b 按字节选取 忽略多字节字符边界,除非也指定了 -n 标志 -c 按字符选取 -d 自定义分隔符,默认为制表符. -f 与-d一起使用,指定显示 ...
- Android Studio集成SVN报错:can't use subversion command line client : svn
Android Studio集成SVN插件,check out出代码后.每次开启都会在右上角出现例如以下错误: Can't use Subversion command line client: sv ...
- 数据库-IO系统性能之衡量性能的几个指标
转自http://storage.it168.com/a2011/0323/1169/000001169755_all.shtml 作为一个数据库管理员,关注系统的性能是日常最重要的工作之一,而在所关 ...
- 发现恶意ip大量访问 可使用命令进行封禁
1. vim /etc/sysconfig/iptables 2.添加箭头指向的语句,ip可以替换, 3. 保存后退出 service iptables save 4.重启 service iptab ...
- Android用http协议上传文件
http协议上传文件一般最大是2M,比较适合上传小于两M的文件 [代码] [Java]代码 001import java.io.File; 002import java.io.FileInp ...
- .NET框架- in ,out, ref , paras使用的代码总结 C#中in,out,ref的作用 C#需知--长度可变参数--Params C#中的 具名参数 和 可选参数 DEMO
C#.net 提供的4个关键字,in,out,ref,paras开发中会经常用到,那么它们如何使用呢? 又有什么区别? 1 in in只用在委托和接口中: 例子: 1 2 3 4 5 6 7 8 9 ...
- mosquitto---config.mk
mosquitto安装时在解压压缩包后生成的文件夹中我们可以找到mosquitto主要配置文件config.mk 这个文件的主要内容: # 是否支持tcpd/libwrap功能. #WITH_WRAP ...
- Pku3673
<span style="color:#6600cc;">/* B - Cow Multiplication Time Limit:1000MS Memory Limi ...
- QQ窗体的控制,同步异步打开360网盘,控制360网盘窗体的移动
1.通过system启动飞秋进程的方式: 2.Windows下杀死进程的方式是:taskkill /f/im QQ.exe.截图例如以下: watermark/2/text/aHR0cDovL2 ...
- Spring Cloud(三):服务提供与调用
上一篇文章我们介绍了eureka服务注册中心的搭建,这篇文章介绍一下如何使用eureka服务注册中心,搭建一个简单的服务端注册服务,客户端去调用服务使用的案例. 案例中有三个角色:服务注册中心.服务提 ...