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是世界上最好的语言
PHP之mb_strstr使用的更多相关文章
- php 基础代码大全(不断完善中)
下面是基础的PHP的代码,不断完善中~ //语法错误(syntax error)在语法分析阶段,源代码并未被执行,故不会有任何输出. /* [命名规则] */ 常量名 类常量建议全大写,单词间用下划线 ...
- PHP7函数大全(4553个函数)
转载来自: http://www.infocool.net/kb/PHP/201607/168683.html a 函数 说明 abs 绝对值 acos 反余弦 acosh 反双曲余弦 addcsla ...
- PHP字符串处理
/*1 字符串格式化 */ $str = ' php '; //清理两边的空格trim();,左边ltrim(); 边rtrin() echo trim($str); //nl2br();将换行符\n ...
- 两千行PHP学习笔记
亲们,如约而至的PHP笔记来啦~绝对干货! 以下为我以前学PHP时做的笔记,时不时的也会添加一些基础知识点进去,有时还翻出来查查. MySQL笔记:一千行MySQL学习笔记http://www.cnb ...
- php错误以及常用笔记
//语法错误(syntax error)在语法分析阶段,源代码并未被执行,故不会有任何输出. /* [命名规则] */ 常量名 类常量建议全大写,单词间用下划线分隔 // MIN_WIDTH 变量名建 ...
- php 学习笔记
//本文转自:http://www.cnblogs.com/ronghua/p/6002995.html //语法错误(syntax error)在语法分析阶段,源代码并未被执行,故不会有任何输出. ...
- PHP - 字符串操作
第8章 字符串处理 学习要点: 1.字符串格式化 2.操作子字符串 3.字符串比较 4.查找替换字符串 5.处理中文字符 在每天的编程工作中,处理.调整以至最后控制字符串是很重要的一部分,一般也认为这 ...
- PHP基础知识点
//语法错误(syntax error)在语法分析阶段,源代码并未被执行,故不会有任何输出. /* [命名规则] */常量名 类常量建议全大写,单词间用下划线分隔 // MIN_WIDTH变量名建议用 ...
- PHP类和函数注释大全
每次要用PHP的某个功能的时候,都要去查一下,于是决定将PHP所有类和函数都整理出来,加上注释 大致实现 将php.jar文件解压,取出目录stubs 将stubs中的所有php文件中的注释去掉,并做 ...
随机推荐
- devexpress停靠菜单
dxDockSite1.Width := 27; dxDockPanel1.DockTo(dxDockSite1, dtLeft, 0); dxDockPanel2.DockTo(dxDockPane ...
- django设置cookie和session
1 设置cookie 本例中应用名称为cookie 模型model from django.db import models from django.db import models class Us ...
- spring+quartz的任务调度
公司网站有个功能是自动投标,还有定时更新用户的排名信息,这些都是spring+quartz实现的. 手机了一些资料,做一个小demo,加深理解,记录一下,以后使用的时候不会出什么问题. 需要的包,主要 ...
- 使用Object.create()实现继承
一.常见继承方式 我们日常开发中常见的继承方式主要有: 1.默认模式: Child.prototype = new Parent(); 2.借用构造函数: function Child(a, b, c ...
- Buffer Pool--内存相关术语
虚拟地址空间(virtual address space): 供应用程序能够申请访问的最大地址空间,32位系统上为4GB,64位系统上是8TB,虚拟地址空间映射的数据不一定存放在物理内存中,还可能存放 ...
- 网页方式访问 QQ 小说书架
iPad.平板电脑 http://bookshelf.html5.qq.com/page?t=pad#!/bookshelf/ iPhone.手机 http://bookshelf.html5.qq. ...
- 自己从0开始学习Unity的笔记 VIII (C#中类继承练习 II)
自己写了一个关于兵种的,因为一直在测试,到底面向对象是个什么玩意...然后就做了这个 namespace 兵种 { class Role //作为父类,构建一个普通角色属性用于继承 { protect ...
- Sql语法高级应用之二:视图
SQL CREATE VIEW 语句 什么是视图? 在 SQL 中,视图是基于 SQL 语句的结果集的可视化的表. 视图包含行和列,就像一个真实的表.视图中的字段就是来自一个或多个数据库中的真实的表中 ...
- 知识记录——Session与Cookie
Session: Session是“会话”的意思,然而,因为http协议是无状态的,那么每次客户端请求服务器端,服务器端都会以“崭新”的页面展示给客户端,这在静态的html页面中是不会存在任何影响,但 ...
- HBase – 探索HFile索引机制
本文由 网易云发布. 作者: 范欣欣 本篇文章仅限内部分享,如需转载,请联系网易获取授权. 01 HFile索引结构解析 HFile中索引结构根据索引层级的不同分为两种:single-level和m ...