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实现的MySQL通用查询程序
Mar 11 PHP
下拉列表多级联动dropDownList示例代码
Jun 27 PHP
PHP中mysqli_affected_rows作用行数返回值分析
Dec 26 PHP
PHP超全局数组(Superglobals)介绍
Jul 01 PHP
PHP经典面试题之设计模式(经常遇到)
Oct 15 PHP
laravel项目利用twemproxy部署redis集群的完整步骤
May 11 PHP
PHP chop()函数讲解
Feb 11 PHP
Yii框架实现对数据库的CURD操作示例
Sep 03 PHP
PHP读取Excel内的图片(phpspreadsheet和PHPExcel扩展库)
Nov 19 PHP
PHP的new static和new self的区别与使用
Nov 27 PHP
php设计模式之模板模式实例分析【星际争霸游戏案例】
Mar 24 PHP
PHP常用字符串函数用法实例总结
Jun 04 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读取目录下所有文件的代码
2008/01/07 PHP
php多功能图片处理类分享(php图片缩放类)
2014/03/14 PHP
十幅图告诉你什么是PHP引用
2015/02/22 PHP
php检查函数必传参数是否存在的实例详解
2017/08/28 PHP
javascript中的107个基础知识收集整理 推荐
2010/03/29 Javascript
jquery做的一个简单的屏幕锁定提示框
2014/03/26 Javascript
jQuery定义插件的方法
2015/12/18 Javascript
基于JQuery实现图片上传预览与删除操作
2016/05/24 Javascript
深入理解JS继承和原型链的问题
2016/12/17 Javascript
深入理解React中何时使用箭头函数
2017/08/23 Javascript
nodejs搭建本地服务器轻松解决跨域问题
2018/03/21 NodeJs
Vue CLI3 开启gzip压缩文件的方式
2018/09/30 Javascript
mpvue项目中使用第三方UI组件库的方法
2018/09/30 Javascript
vue 路由守卫(导航守卫)及其具体使用
2020/02/25 Javascript
[57:22]完美世界DOTA2联赛PWL S2 FTD vs PXG 第二场 11.27
2020/12/01 DOTA
[52:02]完美世界DOTA2联赛PWL S2 FTD.C vs SZ 第一场 11.27
2020/11/30 DOTA
[05:37]DOTA2-DPC中国联赛 正赛 Elephant vs iG 选手采访
2021/03/11 DOTA
Python的条件语句与运算符优先级详解
2015/10/13 Python
python生成不重复随机数和对list乱序的解决方法
2018/04/09 Python
python实现将一个数组逆序输出的方法
2018/06/25 Python
利用Python+阿里云实现DDNS动态域名解析的方法
2019/04/01 Python
详解pandas.DataFrame中删除包涵特定字符串所在的行
2019/04/04 Python
python实现名片管理系统项目
2019/04/26 Python
numpy 声明空数组详解
2019/12/05 Python
Python实现病毒仿真器的方法示例(附demo)
2020/02/19 Python
PyQt5多线程防卡死和多窗口用法的实现
2020/09/15 Python
Django与AJAX实现网页动态数据显示的示例代码
2021/02/24 Python
纯css3实现思维导图样式示例
2018/11/01 HTML / CSS
教师实习期自我鉴定
2013/10/06 职场文书
企业授权委托书范本
2014/09/22 职场文书
2015年司机工作总结
2015/04/23 职场文书
商务信函英语问候语
2015/11/10 职场文书
标会主持词应该怎么写?
2019/08/15 职场文书
Html5页面播放M4a音频文件
2021/03/30 HTML / CSS
用golang如何替换某个文件中的字符串
2021/04/25 Golang
MYSQL 无法识别中文的永久解决方法
2021/06/03 MySQL