首页 期权学习期权知识正文

PHP strstr() 函数

xiaojiucai 期权知识 2020-08-17 538 0

定义和用法

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;
?>

输出:of the 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

原文链接:https://www.qiquanji.com/post/8552.html

本站声明:网站内容来源于网络,如有侵权,请联系我们,我们将及时处理。

微信扫码关注

更新实时通知

版权声明

本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。

评论