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;
}

文章参考

转载注明出处

最新文章

  1. python之浅拷贝和深拷贝
  2. python描述符理解
  3. 基于存储过程的MVC开源分页控件--LYB.NET.SPPager
  4. Java将文件转为字节数组
  5. Go-Agent部署与FQ教程(2016-10-28)
  6. CSS3 选择器——基本选择器
  7. itertools 介绍
  8. cocos2d 遍历CCAarray
  9. DropDownList的多级联动
  10. C++智能指针(auto_ptr)详解
  11. C#实现动态网站伪静态,使seo更友好
  12. WPF与输入法冲突研究之一:百度输入法会导致WPF程序的崩溃!
  13. win8vs2012创建自带sqlServer数据库出错
  14. python-冒泡排序,升序、降序
  15. 【Java集合的详细研究4】Java中如何遍历Map对象的4种方法
  16. ajax请求跨域
  17. 在Activity中响应ListView内部按钮的点击事件的两种方法
  18. ThinkPHP执行调用存储过程添加日志
  19. ROS知识(20)----使用Master_API查询Master管理的节点话题服务内容
  20. 【monkeyrunner】monkeyrunner 常见问题

热门文章

  1. 创建jdk8基础镜像
  2. C#List的创建例程
  3. ceph luminous 新功能之内置 dashboard
  4. 初识阿里开源诊断工具Arthas
  5. 如何外部访问你的本地网站natapp
  6. robot framework学习笔记之二———变量
  7. USB-Redirector-Technician 永久破解版(USB设备映射软件)
  8. java_对象序列化
  9. Tomcat 基础优化
  10. shell-012:批量创建用户