PHP之mb_strrpos使用
mb_strrpos
- (PHP 4 >= 4.0.6, PHP 5, PHP 7)
- mb_strrpos — Find position of last occurrence of a string in a string
- mb_strrpos — 查找字符串在一个字符串中最后出现的位置
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.
//基于字符数执行一个多字节安全的 strrpos() 操作。 needle 的位置是从 haystack 的开始进行统计的。 第一个字符的位置是 0,第二个字符的位置是 1。
Parameters
haystack
- The string being checked, for the last occurrence of needle
- 查找 needle 在这个 string 中最后出现的位置。
needle
- The string to find in haystack.
- 在 haystack 中查找这个 string。
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.
- 可以用于指定 string 里从任意字符数开始进行搜索。 负数的值将导致搜索会终止于指向 string 末尾的任意点。
encoding
- The encoding parameter is the character encoding. If it is omitted, the internal character encoding value will be used.
- encoding 参数为字符编码。如果省略,则使用内部字符编码。
Return Values
- Returns the numeric position of the last occurrence of needle in the haystack string. If needle is not found, it returns FALSE.
- 返回 string 的 haystack 中,needle 最后出现位置的数值。 如果没有找到 needle,它将返回 FALSE。
Example
<?php
/**
* Created by PhpStorm.
* User: zhangrongxiang
* Date: 2018/2/4
* Time: 下午11:02
*/
$test = "万物皆对象,everything is object";
echo strlen( $test ) . PHP_EOL; //38 = 6*3 = 20
echo mb_strlen( $test ) . PHP_EOL;//26 = 6 + 20
echo mb_strrpos( $test, '对象', 1 ) . PHP_EOL; // 3
echo mb_strrpos( $test, 'object', 2 ) . PHP_EOL; // 20
echo mb_strrpos( $test, '对象', - 1 ) . PHP_EOL; // 3
echo mb_strrpos( $test, '对象', - mb_strlen( $test ) + 10 ) . PHP_EOL; // 3
echo mb_strrpos( $test, 'object', - 1 ) . PHP_EOL; // 20
echo mb_strrpos( $test, 'object', - 7 ) . PHP_EOL; // false
echo mb_strrpos( $test, '万物皆对象' ) . PHP_EOL; // 0
//运算符优先级!! 赋值 < 比较
if ( ( $position = mb_strrpos( $test, "万物皆对象" ) ) !== false ) {
//万物皆对象
echo mb_substr( $test, $position, 5 ) . PHP_EOL;
}
$str = "https://github.com/zhangrxiang";
if ( ( $position = mb_strrpos( $str, "/" ) ) !== false ) {
//zhangrxiang
echo mb_substr( $str, $position + 1 ) . PHP_EOL;
}
$str = "/Users/zhangrongxiang/WorkSpace/phpProjects/PHPTEST/2018/02/04/mb_strrpos.php";
if ( ( $position = mb_strrpos( $str, "/" ) ) !== false ) {
//mb_strrpos.php
echo mb_substr( $str, $position + 1 ) . PHP_EOL;
}
文章参考
转载注明出处
PHP之mb_strrpos使用的更多相关文章
- 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配置详解
[PHP] ;;;;;;;;;;;;;;;;;;; ; About php.ini ; ;;;;;;;;;;;;;;;;;;; ; This file controls many aspects of ...
- 最完整PHP.INI中文版
;;;;;;;;;;;;;;;;;;; 关于php.ini ;;;;;;;;;;;;;;;;;;;; 这个文件必须命名为'php.ini'并放置在httpd.conf中PHPINIDir指令指定的目录 ...
- Web服务器上可能被包含或被请求的不同脚本源代码文件
Web服务器上可能被包含或被请求的不同脚本源代码文件的大致数量(建议值为1024~4096). ; 如果你不能确定,则设为 0 :此设定主要用于拥有数千个源文件的站点. apc.optimizatio ...
- php错误以及常用笔记
//语法错误(syntax error)在语法分析阶段,源代码并未被执行,故不会有任何输出. /* [命名规则] */ 常量名 类常量建议全大写,单词间用下划线分隔 // MIN_WIDTH 变量名建 ...
- php 学习笔记
//本文转自:http://www.cnblogs.com/ronghua/p/6002995.html //语法错误(syntax error)在语法分析阶段,源代码并未被执行,故不会有任何输出. ...
- php配置文件php.ini 中文版
;;;;;;;;;;;;;;;; 简介 ;;;;;;;;;;;;;;;;; 本文并非是对英文版 php.ini 的简单翻译,而是参考了众多资料以后,结合自己的理解,增加了许多内容,; 包括在原有 ph ...
随机推荐
- [翻译]Event Handler Description 事件处理描述
Event Handler Description 事件处理描述 (自定义控件) How should a new event handler be defined if it does not ...
- Android-广播总结
1.发送广播: 其实发送广播属于隐式意图 1.1.系统发出的广播(有序广播/无序广播) 1.2自己发出的广播(有序广播/无序广播) 2.订阅广播: 2.1.AndroidManifest.xml形式订 ...
- SqlerMonitor-复制
在复制系统中因为一些配置上失误和人为的失误操作导致复制堵塞,Sqler Monitor 新增加了分析复制延迟邮件,配合复制错误监控邮件和延迟邮件,和复制元数据采集 可以在第一时间准确定位到问题,适合大 ...
- 推荐两款国人开发的html前段框架
1.http://www.h-ui.net/ H-ui前端框架官方网站 2.http://www.builive.com/ BUI是基于JQuery的富客户端UI框架
- ASP.NET Core根据环境切换NLog配置
1.新建NLog配置文件,名称分别为nlog.config和nlog.debug.config <?xml version="1.0"?> <nlog xmlns ...
- Tomcat绿色版启动"startup.bat"一闪问题的解决方法!
进入DOS窗口,运行"startup.bat",会出现错误提示,我是win7 64位,提示“JRE_HOME”设置不正确.于是进入环境变量配置,设置“JRE_HOME”项,随后保存 ...
- BZOJ 1091--切割多边形(几何&枚举)
1091: [SCOI2003]切割多边形 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 356 Solved: 157[Submit][Status ...
- python数据类型详解(全面)
python数据类型详解 目录1.字符串2.布尔类型3.整数4.浮点数5.数字6.列表7.元组8.字典9.日期 1.字符串1.1.如何在Python中使用字符串a.使用单引号(')用单引号括起来表示字 ...
- C++多线程编程二
1. 死锁与解锁: #include <iostream> #include <thread> #include <mutex> using namespace s ...
- Spring Boot 之 Hello World 战记
1. Maven创建SpringBoot项目 2. application.properties spring.session.store-type=none // 解决默认的30+编译错误 3. d ...