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 相关文章推荐
实现“上一页”和“下一页按钮
Oct 09 PHP
php将时间差转换为字符串提示
Sep 07 PHP
PHP连接MongoDB示例代码
Sep 06 PHP
如何用php生成扭曲及旋转的验证码图片
Jun 07 PHP
php实现基于微信公众平台开发SDK(demo)扩展的方法
Dec 22 PHP
示例详解Laravel的注册重构
Aug 14 PHP
PHP实现页面静态化的超简单方法
Sep 06 PHP
PHP实现的同步推荐操作API接口案例分析
Nov 30 PHP
Zend Framework入门教程之Zend_Mail用法示例
Dec 08 PHP
php结合redis高并发下发帖、发微博的实现方法
Dec 15 PHP
PHP那些琐碎的知识点(整理)
May 20 PHP
php去除数组中为0的元素的实例分析
Nov 17 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
咖啡语言
2021/03/03 咖啡文化
PHP迅雷、快车、旋风下载专用链转换代码
2010/06/15 PHP
PHP+jQuery+Ajax实现用户登录与退出
2015/04/27 PHP
php实现生成验证码实例分享
2016/04/10 PHP
PHP中md5()函数的用法讲解
2019/03/30 PHP
jQuery创建插件的代码分析
2011/04/14 Javascript
javascript游戏开发之《三国志曹操传》零部件开发(一)让静态人物动起来
2013/01/23 Javascript
一个jquery实现的不错的多行文字图片滚动效果
2014/09/28 Javascript
javascript十六进制及二进制转化的方法
2015/05/06 Javascript
12个非常实用的JavaScript小技巧【推荐】
2016/05/18 Javascript
JavaScript  event对象整理及详细介绍
2016/10/10 Javascript
AngularJS通过ng-route实现基本的路由功能实例详解
2016/12/13 Javascript
AngularJs导出数据到Excel的示例代码
2017/08/11 Javascript
js链表操作(实例讲解)
2017/08/29 Javascript
jquery 给动态生成的标签绑定事件的几种方法总结
2018/02/24 jQuery
JavaScript使用math.js进行精确计算操作示例
2018/06/19 Javascript
vue侧边栏动态生成下级菜单的方法
2018/09/07 Javascript
vue-cli3+ts+webpack实现多入口多出口功能
2019/05/30 Javascript
Vue循环中多个input绑定指定v-model实例
2020/08/31 Javascript
[01:11:27]2018DOTA2亚洲邀请赛小组赛 A组加赛 Newbee vs Optic
2018/04/03 DOTA
[01:01:52]完美世界DOTA2联赛PWL S2 GXR vs Magma 第二场 11.25
2020/11/26 DOTA
python实现批量转换文件编码(批转换编码示例)
2014/01/23 Python
python实现用户答题功能
2018/01/17 Python
python实现简单日期工具类
2019/04/24 Python
numpy.ndarray 实现对特定行或列取值
2019/12/05 Python
tensorflow实现打印ckpt模型保存下的变量名称及变量值
2020/01/04 Python
在pycharm创建scrapy项目的实现步骤
2020/12/01 Python
CSS3 please 跨浏览器的CSS3产生器
2010/03/14 HTML / CSS
澳大利亚最大的女装零售商:Millers
2017/09/10 全球购物
船餐厅和泰晤士河餐饮游轮:Bateaux London
2018/03/19 全球购物
俄罗斯运动鞋商店:Sneakerhead
2018/05/10 全球购物
班组安全员工作职责
2014/02/01 职场文书
铁路工务反思材料
2014/02/07 职场文书
棉花姑娘教学反思
2014/02/15 职场文书
大型主题婚礼活动策划方案
2014/09/15 职场文书
工作态度怎么写
2015/06/25 职场文书