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 相关文章推荐
Email+URL的判断和自动转换函数
Oct 09 PHP
PHP语法速查表
Jan 02 PHP
mysql+php分页类(已测)
Mar 31 PHP
discuz的php防止sql注入函数
Jan 17 PHP
一个PHP分页类的代码
May 18 PHP
PHP之数组学习
May 29 PHP
PHP采集腾讯微博的实现代码
Jan 19 PHP
apache php模块整合操作指南
Nov 16 PHP
解析CI即CodeIgniter框架在Nginx下的重写规则
Jun 03 PHP
php去除字符串中空字符的常用方法小结
Mar 17 PHP
php的4种常见运行方式
Mar 20 PHP
使用composer 安装 laravel框架的方法图文详解
Aug 02 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
第八节--访问方式
2006/11/16 PHP
php检测文本的编码
2015/07/26 PHP
PHP入门教程之PHP操作MySQL的方法分析
2016/09/11 PHP
php app支付宝回调(异步通知)详解
2018/07/25 PHP
解密效果
2006/06/23 Javascript
javascript自适应宽度的瀑布流实现思路
2013/02/20 Javascript
让js弹出窗口居前显示的实现方法
2013/07/10 Javascript
jquery validate添加自定义验证规则(验证邮箱 邮政编码)
2013/12/04 Javascript
js 限制input只能输入数字、字母和汉字等等
2013/12/18 Javascript
什么是Node.js?Node.js详细介绍
2014/06/01 Javascript
jquery中toggle函数交替使用问题
2015/06/22 Javascript
js+css实现的圆角边框TAB选项卡滑动门代码分享(2款)
2015/08/26 Javascript
Node.js静态文件服务器改进版
2016/01/10 Javascript
bootstrap读书笔记之CSS组件(上)
2016/10/17 Javascript
Jquery Easyui验证组件ValidateBox使用详解(20)
2016/12/18 Javascript
js编写三级联动简单案例
2016/12/21 Javascript
vue移动端屏幕适配详解
2019/04/30 Javascript
JS学习笔记之数组去重实现方法小结
2019/05/29 Javascript
node.JS事件机制与events事件模块的使用方法详解
2020/02/06 Javascript
vue 页面跳转的实现方式
2021/01/12 Vue.js
Python3安装Scrapy的方法步骤
2017/11/23 Python
浅谈python写入大量文件的问题
2018/11/09 Python
使用python list 查找所有匹配元素的位置实例
2019/06/11 Python
python实现简单五子棋游戏
2019/06/18 Python
简单了解python代码优化小技巧
2019/07/08 Python
python判断变量是否为int、字符串、列表、元组、字典的方法详解
2020/02/13 Python
python闭包与引用以及需要注意的陷阱
2020/09/18 Python
6PM官网:折扣鞋、服装及配饰
2018/08/03 全球购物
Monica Vinader官网:英国轻奢珠宝品牌
2020/02/05 全球购物
宏碁西班牙官网:Acer西班牙
2021/01/08 全球购物
青年志愿者事迹材料
2014/02/07 职场文书
沙滩主题婚礼活动策划方案
2014/09/15 职场文书
浪漫婚礼主题活动策划方案
2014/09/15 职场文书
个人租房协议书
2014/11/28 职场文书
2014年医务科工作总结
2014/12/18 职场文书
九年级化学教学反思
2016/02/22 职场文书