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使用的更多相关文章

  1. php 基础代码大全(不断完善中)

    下面是基础的PHP的代码,不断完善中~ //语法错误(syntax error)在语法分析阶段,源代码并未被执行,故不会有任何输出. /* [命名规则] */ 常量名 类常量建议全大写,单词间用下划线 ...

  2. PHP7函数大全(4553个函数)

    转载来自: http://www.infocool.net/kb/PHP/201607/168683.html a 函数 说明 abs 绝对值 acos 反余弦 acosh 反双曲余弦 addcsla ...

  3. 两千行PHP学习笔记

    亲们,如约而至的PHP笔记来啦~绝对干货! 以下为我以前学PHP时做的笔记,时不时的也会添加一些基础知识点进去,有时还翻出来查查. MySQL笔记:一千行MySQL学习笔记http://www.cnb ...

  4. PHP配置详解

    [PHP] ;;;;;;;;;;;;;;;;;;; ; About php.ini ; ;;;;;;;;;;;;;;;;;;; ; This file controls many aspects of ...

  5. 最完整PHP.INI中文版

    ;;;;;;;;;;;;;;;;;;; 关于php.ini ;;;;;;;;;;;;;;;;;;;; 这个文件必须命名为'php.ini'并放置在httpd.conf中PHPINIDir指令指定的目录 ...

  6. Web服务器上可能被包含或被请求的不同脚本源代码文件

    Web服务器上可能被包含或被请求的不同脚本源代码文件的大致数量(建议值为1024~4096). ; 如果你不能确定,则设为 0 :此设定主要用于拥有数千个源文件的站点. apc.optimizatio ...

  7. php错误以及常用笔记

    //语法错误(syntax error)在语法分析阶段,源代码并未被执行,故不会有任何输出. /* [命名规则] */ 常量名 类常量建议全大写,单词间用下划线分隔 // MIN_WIDTH 变量名建 ...

  8. php 学习笔记

    //本文转自:http://www.cnblogs.com/ronghua/p/6002995.html //语法错误(syntax error)在语法分析阶段,源代码并未被执行,故不会有任何输出. ...

  9. php配置文件php.ini 中文版

    ;;;;;;;;;;;;;;;; 简介 ;;;;;;;;;;;;;;;;; 本文并非是对英文版 php.ini 的简单翻译,而是参考了众多资料以后,结合自己的理解,增加了许多内容,; 包括在原有 ph ...

随机推荐

  1. HDU1412:{A} + {B}

    Problem Description 给你两个集合,要求{A} + {B}. 注:同一个集合中不会有两个相同的元素.   Input 每组输入数据分为三行,第一行有两个数字n,m(0<n,m& ...

  2. 简述负载均衡和CDN技术

    曾经见到知乎上有人问“为什么像facebook这类的网站需要上千个工程师维护?”,下面的回答多种多样,但总结起来就是:一个高性能的web系统需要从无数个角度去考虑他,大到服务器的布局,小到软件中某个文 ...

  3. Oracle Submit Request - 请求的调用方法: FND_REQUEST.SUBMIT_REQUEST

    废话: 有一段时间没搞过开发了,做项目又要重新找回点开发的记忆.重新拾回一点点零碎. 跑多了产线,配置的一些参数也忘记得差不多了,长时间没动就是易遗忘,找点资料做个笔记就是时间保镖.   正题: FN ...

  4. Android-有序广播

    在之前的博客,Android-广播概念,中介绍了(广播和广播接收者)可以组件与组件之间进行通讯,有两种类型的广播(无序广播 和 有序广播),这篇博客就来讲解有序广播的代码实现: 有序广播:接收者 可以 ...

  5. 关于如何参与到开源项目中《How To Succeed In Open Source ( In Ways You Haven't Considered Yet )》

    转自:http://gaslight.co/blog/how-to-succeed-in-open-source-in-ways-you-havent-considered-yet It’s Easy ...

  6. C#使用LitJson对Json数据解析

    JSON 介绍 JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.它基于JavaScript(Standard ECMA-262 3rd Edition - ...

  7. Cesium Language (CZML) 入门2 — CZML Content(CZML的内容)

    原文:https://github.com/AnalyticalGraphicsInc/cesium/wiki/CZML-Content 以下是描述CZML文档或者流中可能存在的内容.要解释CZML文 ...

  8. 限制html文本框input只能输入数字和小数点

    代码: <input type="text" class="txt" name="qty" value="" on ...

  9. LockBox的安装

    LockBox是一套加密解密库,下载地址:http://sourceforge.net/projects/tplockbox/ 我的安装的操作系统:win7 64位 安装步骤如下: 一,安装: 安装时 ...

  10. 一次mysql主从同步问题及解决过程

    Normal 0 7.8 磅 0 2 false false false EN-US ZH-CN X-NONE MicrosoftInternetExplorer4 由于经常被抓取文章内容,在此附上博 ...