php学习笔记之mb_strstr的基本使用


Posted in PHP onFebruary 03, 2018

前言

本文主要介绍了关于php之mb_strstr基本使用的相关内容,分享出来供大家参考学习,下面话不多说了,来一起看看详细的介绍吧。

mb_strstr

  • (PHP 5 >= 5.2.0, PHP 7)
  • mb_strstr — Finds first occurrence of a string within another
  • 查找字符串在另一个字符串里的首次出现

Description

string mb_strstr ( 
 string $haystack , 
 string $needle [, 
 bool $before_needle = false [, 
 string $encoding =mb_internal_encoding() ]] 
 )

//mb_strstr() finds the first occurrence of needle in haystack and returns the portion of haystack. If needle is not found, it returns FALSE.
//mb_strstr() 查找了 needle 在 haystack 中首次的出现并返回 haystack 的一部分。 如果 needle 没有找到,它将返回 FALSE。

Parameters

haystack

  • The string from which to get the first occurrence of needle
  • 要获取 needle 首次出现的字符串。

needle

  • The string to find in haystack
  • 在 haystack 中查找这个字符串。

before_needle

  • Determines which portion of haystack this function returns. If set to TRUE, it returns all of haystack from the beginning to the first occurrence of needle (excluding needle). If set to FALSE, it returns all of haystack from the first occurrence of needle to the end (including needle).
  • 决定这个函数返回 haystack 的哪一部分。 如果设置为 TRUE,它返回 haystack 中从开始到 needle 出现位置的所有字符(不包括 needle)。 如果设置为 FALSE,它返回 haystack 中 needle 出现位置到最后的所有字符(包括了 needle)。

encoding

  • Character encoding name to use. If it is omitted, internal character encoding is used.
  • 要使用的字符编码名称。 如果省略该参数,将使用内部字符编码。

Return Values

  • Returns the portion of haystack, or FALSE if needle is not found.
  • 返回 haystack 的一部分,或者 needle 没找到则返回 FALSE。

Examples

<?php
/**
 * Created by PhpStorm.
 * User: zhangrongxiang
 * Date: 2018/2/1
 * Time: 下午10:27
 */

//* * If set to true, it returns all of haystack from the beginning to the first occurrence of needle.
$strstr = mb_strstr( "hello china", "ll", true );
echo $strstr . PHP_EOL; //he

//* If set to false, it returns all of haystack from the first occurrence of needle to the end,
$strstr = mb_strstr( "hello china", "ll", false );
echo $strstr . PHP_EOL;//llo china

//hello china
echo mb_strstr( "hello china", "ll", true ) . mb_strstr( "hello china", "ll", false ) . PHP_EOL;

$strstr = mb_strstr( "hello China,hello PHP", "ll", true );
echo $strstr . PHP_EOL; //he

$strstr = mb_strstr( "hello China,hello PHP", "ll", false );
echo $strstr . PHP_EOL; //llo China,hello PHP

$strstr = mb_strstr( "PHP是世界上最好的语言?", "最好", true );
echo $strstr.PHP_EOL; //PHP是世界上
$strstr = mb_strstr( "PHP是世界上最好的语言?", "最好", false );
echo $strstr.PHP_EOL; //最好的语言?

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,如果有疑问大家可以留言交流,谢谢大家对三水点靠木的支持。

PHP 相关文章推荐
浅谈PHP语法(1)
Oct 09 PHP
PHP+XML 制作简单的留言本 图文教程
Nov 02 PHP
深入理解PHP之require/include顺序 推荐
Jan 02 PHP
php中获取关键词及所属来源搜索引擎名称的代码
Feb 15 PHP
PHP新手入门学习方法
May 08 PHP
php开启与关闭错误提示适用于没有修改php.ini的权限
Oct 16 PHP
PHP实现文件上传和多文件上传
Dec 24 PHP
编写PHP脚本清除WordPress头部冗余代码的方法讲解
Mar 01 PHP
PHP简单留言本功能实现代码
Jun 09 PHP
php实现数组中出现次数超过一半的数字的统计方法
Oct 14 PHP
php实现每日签到功能
Nov 29 PHP
Thinkphp 框架扩展之标签库驱动原理与用法分析
Apr 23 PHP
php通过pecl方式安装扩展的实例讲解
Feb 02 #PHP
PHP实现对图片的反色处理功能【测试可用】
Feb 01 #PHP
php 删除一维数组中某一个值元素的操作方法
Feb 01 #PHP
基于php双引号中访问数组元素报错的解决方法
Feb 01 #PHP
PHP运用foreach神奇的转换数组(实例讲解)
Feb 01 #PHP
PHP双向链表定义与用法示例
Jan 31 #PHP
基于PHP实现的多元线性回归模拟曲线算法
Jan 30 #PHP
You might like
一个非常实用的php文件上传类
2017/07/04 PHP
[IE&amp;FireFox兼容]JS对select操作
2007/01/07 Javascript
JavaScript的parseInt 进制问题
2009/05/07 Javascript
基于jquery自定义的漂亮单选按钮RadioButton
2013/11/19 Javascript
Jquery Post处理后不进入回调的原因及解决方法
2014/07/15 Javascript
原生JS封装Ajax插件(同域、jsonp跨域)
2016/05/03 Javascript
Angular的$http的ajax的请求操作(推荐)
2017/01/10 Javascript
基于JS实现移动端向左滑动出现删除按钮功能
2017/02/22 Javascript
基于Vue实现支持按周切换的日历
2020/09/24 Javascript
vue router-link传参以及参数的使用实例
2017/11/10 Javascript
vue实现导航栏效果(选中状态刷新不消失)
2017/12/13 Javascript
JavaScript中的ES6 Proxy的具体使用
2019/06/16 Javascript
JS字符串与二进制的相互转化实例代码详解
2019/06/28 Javascript
在vue中实现清除echarts上次保留的数据(亲测有效)
2020/09/09 Javascript
[01:01:24]LGD vs Fnatic 2018国际邀请赛小组赛BO2 第一场 8.18
2018/08/19 DOTA
python实现员工管理系统
2018/01/11 Python
Python multiprocessing多进程原理与应用示例
2019/02/28 Python
解决Django中修改js css文件但浏览器无法及时与之改变的问题
2019/08/31 Python
pytorch torchvision.ImageFolder的用法介绍
2020/02/20 Python
如何使用Python调整图像大小
2020/09/26 Python
pycharm进入时每次都是insert模式的解决方式
2021/02/05 Python
HTML5新增form控件和表单属性实例代码详解
2019/05/15 HTML / CSS
HTML5跳转小程序wx-open-launch-weapp的示例代码
2020/07/16 HTML / CSS
日本动漫周边服饰销售网站:Atsuko
2019/12/16 全球购物
土木工程毕业生推荐信
2013/10/28 职场文书
致跳高运动员广播稿
2014/01/13 职场文书
甜点店创业计划书
2014/01/27 职场文书
2014年国培研修感言
2014/03/09 职场文书
关于青春的演讲稿
2014/05/05 职场文书
俞敏洪北大演讲稿
2014/05/22 职场文书
电子专业求职信
2014/06/19 职场文书
暑假社会实践证明格式
2014/10/28 职场文书
入伍通知书
2015/04/23 职场文书
个人更名证明
2015/06/23 职场文书
2015年秋季学校开学标语
2015/07/16 职场文书
美容院管理规章制度
2015/08/05 职场文书