PHP之mb_substr_count使用
mb_substr_count
- (PHP 4 >= 4.3.0, PHP 5, PHP 7)
- mb_substr_count — Count the number of substring occurrences
- mb_substr_count — 统计字符串出现的次数
Description
int mb_substr_count (
string $haystack ,
string $needle [,
string $encoding = mb_internal_encoding() ]
)
//Counts the number of times the needle substring occurs in the haystack string.
//统计子字符串 needle 出现在字符串 haystack 中的次数。
Parameters
haystack
- The string being checked.
- 要检查的字符串。
needle
- The string being found.
- 待查找的字符串。
encoding
- The encoding parameter is the character encoding. If it is omitted, the internal character encoding value will be used.
- encoding 参数为字符编码。如果省略,则使用内部字符编码。
Return Values
- The number of times the needle substring occurs in the haystack string.
- 子字符串 needle 出现在字符串 haystack 中的次数。
Examples
<?php
/**
* Created by PhpStorm.
* User: zhangrongxiang
* Date: 2018/1/31
* Time: 下午10:07
*/
echo mb_substr_count( "This is a test", "is" ) . PHP_EOL; // 输出 2
echo mb_substr_count( "This is a test", " " ) . PHP_EOL; // 输出 3
echo mb_substr_count( "hello 中国! 中国 ! 中国! hello", "中国" ) . PHP_EOL; //3
echo mb_substr_count( "hello 中国! 中国 ! 中国! hello", "中国", "gbk" ) . PHP_EOL; //3
echo mb_substr_count( "hello 中国! 中国 ! 中国! hello", "中国", "utf-8" ) . PHP_EOL; //3
echo mb_substr_count( "hello 中国! 中国 ! 中国! hello", "中国", "ascii" ) . PHP_EOL; //3
echo "strlen : " . mb_strlen( "hello 中国! 中国 ! 中国! hello" ) . PHP_EOL; //24
echo "mb_strlen : " . strlen( "hello 中国! 中国 ! 中国! hello" ) . PHP_EOL; //40 = 8*3 + 16
echo substr_count( "hello 中国! 中国 ! 中国! hello", "中国" ) . PHP_EOL; //3
echo substr_count( "hello 中国! 中国 ! 中国! hello", "中国", 2, 10 ) . PHP_EOL; //1
文章参考
转载注明出处
PHP之mb_substr_count使用的更多相关文章
- 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配置详解
[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)在语法分析阶段,源代码并未被执行,故不会有任何输出. ...
随机推荐
- TFS 2015新功能之一,当前迭代查询标记
TFS 2015发布在即,有幸作为MVP提前获得了TFS的RTM版本,下面就TFS 2015的新功能做一些介绍: TFS 2015新功能之一,当前迭代查询标记 在TFS的查询中,可以将" ...
- .Net 数据缓存浅析
目录 1场景出发 1.1数据请求 1.2优化改进 2缓存 3缓存进阶 3.1缓存清除 3.2有效性 3.3线程安全 4适用场景和优劣 4.1适用场景 4.2优劣 5结语 1场景出发 1.1数据请求 小 ...
- 【文文殿下】Manache算法-学习笔记
Manache算法 定义:是一个判断回文子串的算法,我们结合例题解释: 题目:给定一个长度为 n 的字符串 S,求其最长回文子串 一个字符串是回文的,当且仅当反转后的串与原串完全相等 分析:对于这个题 ...
- java下载文件注意点
前台: 不建议使用ajax,可以使用window.location.href 后台: 三个参数--> response path filename--filename如果要防止乱码,可以用Str ...
- COGS1752. [BOI2007]摩基亚Mokia(CDQ,树状数组)
题目描述 摩尔瓦多的移动电话公司摩基亚(Mokia)设计出了一种新的用户定位系统.和其他的定位系统一样,它能够迅速回答任何形如“用户C的位置在哪?”的问题,精确到毫米.但其真正高科技之处在于,它能够回 ...
- LOJ#2070. 「SDOI2016」平凡的骰子(计算几何)
题面 传送门 做一道题学一堆东西不管什么时候都是美好的体验呢-- 前置芝士 混合积 对于三个三维向量\(a,b,c\),定义它们的混合积为\((a\times b)\cdot c\),其中$\time ...
- 【Node】node.js实现服务器的反向代理,解决跨域问题
跨域对于前端来说是一个老大难的问题,许多方法如jsonp.document.domain + iframe...都有或多或少的问题,一个最佳实践就是通过服务器nginx做反向代理,但奈何不懂相关知识, ...
- 算法导论-MIT笔记
第一部分 Analysis of Algorithms 算法分析是关于计算机程序性能(performance)和资源利用的理论研究 1 What's more important than perfo ...
- Win10将用户名修改为英文
前言 最近重装了一次Win10系统,手贱地在引导里设置了中文的用户名.使用微软账户进行登录后,Win10以这个中文名建立了用户的文件夹,使得少数软件安装或使用过程中,保存路径不支持中文路径,从而报错, ...
- bash: wget: command not found
有些VPS执行wget命令下载时,提示-bash: wget: command not found错误,其实这是由于系统中没有安装wget,我们只要执行安装命令安装即可. yum -y install ...