php strstr >0,PHP strstr() 函数

8e7aafcc76c50f5b80b557f5062c2a76.png

定义和用法

strstr() 函数搜索字符串在另一字符串中是否存在,如果是,返回该字符串及剩余部分,否则返回 FALSE。

注释:该函数是二进制安全的。该函数是区分大小写的。如需进行不区分大小写的搜索,请使用 stristr() 函数。

语法

strstr(string,search,before_search)

参数描述

string必需。规定被搜索的字符串。

search必需。规定要搜索的字符串。如果该参数是数字,则搜索匹配该数字对应的 ASCII 值的字符。

before_search可选。一个默认值为 "false" 的布尔值。如果设置为 "true",它将返回 search 参数第一次出现之前的字符串部分。

示例01:<?php

$str = "The scene of the women's volleyball match is so touching: she walked through the net to hold the injured and crying opponent in her arms.";

$newstr = strstr($str,"of");  //从of第一次出现的位置开始选取,到最后的字符串   strstr()函数是区分大小写的,

echo $newstr;

?>

输出:ofthe women's volleyball match is so touching: she walked through the net to hold the injured and crying opponent in her arms.

示例02:<?php

$str2 = "Select the string before the first occurrence";

//第三个参数串默认是false(选取第一次出现的位置之后的字符串);如果第三个参数改成true,(选取第一次出现的位置之前的字符串)

$gostr = strstr($str2,"the",true);

echo $gostr;

?>

输出:Select

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值