PHP之mb_strripos使用
mb_strripos
- (PHP 4 >= 4.0.6, PHP 5, PHP 7)
 - mb_strrpos — Find position of last occurrence of a string in a string
 - mb_strripos — 大小写不敏感地在字符串中查找一个字符串最后出现的位置
 
Description
int mb_strrpos (
    string $haystack ,
    string $needle [,
    int $offset = 0 [,
    string $encoding = mb_internal_encoding() ]]
    )
//Performs a multibyte safe strrpos() operation based on the number of characters. needle position is counted from //the beginning of haystack. First character's position is 0. Second character position is 1.
//mb_strripos() 基于字符数执行一个多字节安全的 strripos() 操作。 needle 的位置是从 haystack 的开始进行统计的。 第一个字符的位置//是 0,第二个字符的位置是 1。 和 mb_strrpos() 不同的是,mb_strripos() 是大小写不敏感的。
Parameters
haystack
- The string being checked, for the last occurrence of needle
 - 查找 needle 在这个字符串中最后出现的位置。
 
needle
- The string to find in haystack.
 - 在 haystack 中查找这个字符串。
 
offset
- May be specified to begin searching an arbitrary number of characters into the string. Negative values will stop searching at an arbitrary point prior to the end of the string.
 - 在 haystack 中开始搜索的位置。
 
encoding
- The encoding parameter is the character encoding. If it is omitted, the internal character encoding value will be used.
 - 使用的字符编码名称。如果省略了,则将使用内部编码。
 
Return Values
- Returns the numeric position of the last occurrence of needle in the haystack string. If needle is not found, it returns FALSE.
 - 返回字符串 haystack 中 needle 最后出现位置的数值。 如果没有找到 needle,它将返回 FALSE。
 
Example
<?php
/**
 * Created by PhpStorm.
 * User: zhangrongxiang
 * Date: 2018/2/5
 * Time: 下午11:00
 */
$str = "Life is short,I use PHP";
$por = mb_strripos( $str, "php", 10 );
echo $por . PHP_EOL; //20
function startsWith( $haystack, $needle ) {
	$res = false;
	if ( mb_strripos( $haystack, $needle, 0, "utf-8" ) === 0 ) {
		$res = true;
	}
	return $res;
}
function endsWith( $haystack, $needle ) {
	$res = false;
	$len = mb_strlen( $haystack );
	$pos = $len - mb_strlen( $needle );
	if ( mb_strripos( $haystack, $needle, 0, "utf-8" ) === $pos ) {
		$res = true;
	}
	return $res;
}
if ( startsWith( $str, "life" ) ) {
	//true
	echo "startsWith($str,life)" . PHP_EOL;
}
if ( startsWith( $str, "php" ) ) {
	echo "startsWith($str,php)" . PHP_EOL;
} else {
	//false
	echo "No startsWith($str,php)" . PHP_EOL;
}
if ( endsWith( $str, "php" ) ) {
	//true
	echo "endsWith($str,php)" . PHP_EOL;
}
if ( endsWith( $str, "life" ) ) {
	echo "endsWith($str,life)" . PHP_EOL;
} else {
	//false
	echo "No endsWith($str,life)" . PHP_EOL;
}
文章参考
转载注明出处
PHP之mb_strripos使用的更多相关文章
- php 基础代码大全(不断完善中)
		
下面是基础的PHP的代码,不断完善中~ //语法错误(syntax error)在语法分析阶段,源代码并未被执行,故不会有任何输出. /* [命名规则] */ 常量名 类常量建议全大写,单词间用下划线 ...
 - PHP7函数大全(4553个函数)
		
转载来自: http://www.infocool.net/kb/PHP/201607/168683.html a 函数 说明 abs 绝对值 acos 反余弦 acosh 反双曲余弦 addcsla ...
 - 两千行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基础知识点
		
//语法错误(syntax error)在语法分析阶段,源代码并未被执行,故不会有任何输出. /* [命名规则] */常量名 类常量建议全大写,单词间用下划线分隔 // MIN_WIDTH变量名建议用 ...
 - PHP类和函数注释大全
		
每次要用PHP的某个功能的时候,都要去查一下,于是决定将PHP所有类和函数都整理出来,加上注释 大致实现 将php.jar文件解压,取出目录stubs 将stubs中的所有php文件中的注释去掉,并做 ...
 - 一个小时学会PHP
		
一.PHP概要 PHP(外文名:PHP: Hypertext Preprocessor,中文名:“超文本预处理器”)是一种通用开源脚本语言.语法吸收了C语言.Java和Perl的特点,利于学习,使用广 ...
 - GeSHi Documentation
		
GeSHi Documentation Version 1.0.8.11 Authors: © 2004 - 2007 Nigel McNie © 2007 - 2012 Benny Baumann ...
 
随机推荐
- 两段 PHP 代码比较优劣
			
// 代码一 public function getPCA($level = false) { $results = array(); $where = $level ? " where f ...
 - Docker Warning : the backing xfs filesystem is formatted without d_type support
			
CentOS7 下安装配置 Docker,遇到如下的WARNING, WARNING: overlay: the backing xfs filesystem is formatted without ...
 - mysql设定或修改密码的三个方法
			
为用户设定密码: 1.mysql>SET PASSWORD FOR 'USERNAME'@'HOST'=PASSWORD('password'); 2.# mysqladmin -uUSERNA ...
 - (zxing.net)二维码QR Code的简介、实现与解码
			
一.简介 二维码QR Code(Quick Response Code)是由Denso公司于1994年9月研制的一种矩阵二维码符号,它具有一维条码及其它二维条码所具有的信息容量大.可靠性高.可表示汉字 ...
 - js判断是移动端还是PC端访问网站
			
window.location.href = /Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent) ? "htt ...
 - Devexpress WPF教程
			
[视频专辑]酷炫界面开发神器DevExpress WPF视频教程(36集全) http://www.devexpresscn.com/post/620.html
 - golang plugin的依赖问题
			
golang plugin的依赖问题 此文中涉及的plugin运行环境为mac 10.14,go版本为1.11 主要是想讨论一下插件依赖的第三方库的问题. 例子是在https://github.com ...
 - Android 推送
			
安卓推送方案及比较 http://www.eoe.cn/news/11955.html ******************************************************** ...
 - php—Smarty-2
			
一.注释 *注释内容* Html注释显示客户端源文件中 Smarty注释不会发给客户端 Smarty的注释主要给模板设计者来看的 二.模板中的变量 l 由php文件分配 1) 普通变量 2) 数 ...
 - BootStrap框架引入文件
			
bootstrap -- 框架 引入需要的 这是外网的------************************************************************* < ...