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五种设计模式小结
Mar 23 PHP
php学习之数据类型之间的转换介绍
Jun 09 PHP
php daddslashes()和 saddslashes()有哪些区别分析
Oct 26 PHP
如何使用php输出时间格式
Aug 31 PHP
PHPMailer的主要功能特点和简单使用说明
Feb 17 PHP
codeigniter上传图片不能正确识别图片类型问题解决方法
Jul 25 PHP
php输出全球各个时区列表的方法
Mar 31 PHP
php+resumablejs实现的分块上传 断点续传功能示例
Apr 18 PHP
CentOS7.0下安装PHP5.6.30服务的教程详解
Sep 29 PHP
PHP token验证生成原理实例分析
Jun 05 PHP
PHP 超级全局变量相关总结
Jun 30 PHP
PHP SESSION跨页面传递失败解决方案
Dec 11 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
模拟flock实现文件锁定
2007/02/14 PHP
php桌面中心(一) 创建数据库
2007/03/11 PHP
php中几种常见安全设置详解
2010/04/06 PHP
php set_time_limit()函数的使用详解
2013/06/05 PHP
定义php常量的详解
2013/06/09 PHP
php检测文本的编码
2015/07/26 PHP
yii2实现分页,带搜索的分页功能示例
2017/01/07 PHP
ajax无刷新动态调用股票信息(改良版)
2008/11/01 Javascript
在javascript中对于DOM的加强
2013/04/11 Javascript
网页前端优化之滚动延时加载图片示例
2013/07/13 Javascript
Javascript浅谈之引用类型
2013/12/18 Javascript
关闭浏览器时提示onbeforeunload事件
2013/12/25 Javascript
jQuery 鼠标经过(hover)事件的延时处理示例
2014/04/14 Javascript
Javascript中对象继承的实现小例
2014/05/12 Javascript
按钮接受回车事件的三种实现方法
2014/06/06 Javascript
node.js中的fs.mkdir方法使用说明
2014/12/17 Javascript
jquery解析json格式数据的方法(对象、字符串)
2015/11/24 Javascript
基于jquery实现瀑布流布局
2020/06/28 Javascript
jQuery插件实现适用于移动端的地址选择器
2016/02/18 Javascript
微信小程序实现皮肤功能(夜间模式)
2017/06/18 Javascript
Nodejs处理异常操作示例
2018/12/25 NodeJs
浅析Python中的getattr(),setattr(),delattr(),hasattr()
2016/06/14 Python
200行自定义python异步非阻塞Web框架
2017/03/15 Python
Python入门之三角函数tan()函数实例详解
2017/11/08 Python
python中set()函数简介及实例解析
2018/01/09 Python
pandas数据分组和聚合操作方法
2018/04/11 Python
python使用ddt过程中遇到的问题及解决方案【推荐】
2018/10/29 Python
Pandas DataFrame数据的更改、插入新增的列和行的方法
2019/06/25 Python
Python-Seaborn热图绘制的实现方法
2019/07/15 Python
Python OrderedDict字典排序方法详解
2020/05/21 Python
Opencv python 图片生成视频的方法示例
2020/11/18 Python
如何用python写个模板引擎
2021/01/14 Python
客服专员岗位职责范本
2015/04/07 职场文书
用React Native制作一个简单的游戏引擎
2021/05/27 Javascript
如何解决flex文本溢出问题小结
2022/07/15 HTML / CSS
Spring Boot 的创建和运行示例代码详解
2022/07/23 Java/Android