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版(3)
Oct 09 PHP
dede全站URL静态化改造[070414更正]
Apr 17 PHP
php adodb分页实现代码
Mar 19 PHP
PHP 木马攻击防御技巧
Jun 13 PHP
一贴学会PHP 新手入门教程
Aug 03 PHP
深入php处理整数函数的详解
Jun 09 PHP
web server使用php生成web页面的三种方法总结
Oct 28 PHP
PHP OPP机制和模式简介(抽象类、接口和契约式编程)
Jun 09 PHP
codeigniter实现get分页的方法
Jul 10 PHP
php三种实现多线程类似的方法
Oct 30 PHP
详解WordPress中用于更新和获取用户选项数据的PHP函数
Mar 08 PHP
php学习笔记之字符串常见操作总结
Jul 16 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
全国FM电台频率大全 - 8 黑龙江省
2020/03/11 无线电
php5 mysql分页实例代码
2008/04/10 PHP
新浪微博API开发简介之用户授权(PHP基础篇)
2011/09/25 PHP
PHP高自定义性安全验证码代码
2011/11/27 PHP
thinkphp微信开发(消息加密解密)
2015/12/02 PHP
学习php设计模式 php实现享元模式(flyweight)
2015/12/07 PHP
[原创]smarty简单模板变量输出方法
2016/07/09 PHP
Yii2主题(Theme)用法详解
2016/07/23 PHP
javascript 写类方式之四
2009/07/05 Javascript
AngularJS ng-blur 指令详解及简单实例
2016/07/30 Javascript
JavaScript性能优化之函数节流(throttle)与函数去抖(debounce)
2016/08/11 Javascript
angularJs关于指令的一些冷门属性详解
2016/10/24 Javascript
运用jQuery写的验证表单(实例讲解)
2017/07/06 jQuery
浅谈JS for循环中使用break和continue的区别
2020/07/21 Javascript
详解vue 组件注册
2020/11/20 Vue.js
Python的内存泄漏及gc模块的使用分析
2014/07/16 Python
Python脚本实现网卡流量监控
2015/02/14 Python
浅谈Python的异常处理
2016/06/19 Python
解决csv.writer写入文件有多余的空行问题
2018/07/06 Python
Python SQL查询并生成json文件操作示例
2018/08/17 Python
用Python中的turtle模块画图两只小羊方法
2019/04/09 Python
python绘制地震散点图
2019/06/18 Python
python基于openpyxl生成excel文件
2020/12/23 Python
香港草莓网土耳其网站:Strawberrynet TR
2017/03/02 全球购物
焊接专业毕业生求职信
2013/10/01 职场文书
客户经理岗位职责
2013/12/08 职场文书
作文评语集锦大全
2014/04/23 职场文书
机房搬迁方案
2014/05/01 职场文书
班级读书活动总结
2014/06/30 职场文书
预备党员自我评价范文
2015/03/04 职场文书
2016寒假假期总结
2015/10/10 职场文书
浅谈:电影《孔子》观后感(范文)
2019/10/14 职场文书
详解Java七大阻塞队列之SynchronousQueue
2021/09/04 Java/Android
天谕手游15杯全调酒配方和调酒券的获得方式
2022/04/06 其他游戏
MySQL串行化隔离级别(间隙锁实现)
2022/06/16 MySQL
MySQL的表级锁,行级锁,排它锁和共享锁
2022/07/15 MySQL