PHP之string之str_word_count()函数使用
str_word_count
- (PHP 4 >= 4.3.0, PHP 5, PHP 7)
- str_word_count — Return information about words used in a string
- str_word_count — 返回字符串中单词的使用情况
Description
mixed str_word_count (
string $string [,
int $format = 0 [,
string $charlist ]]
)
/**
Counts the number of words inside string. If the optional format is not specified, then the return value will be an integer representing the number of words found. In the event the format is specified, the return value will be an array, content of which is dependent on the format. The possible value for the format and the resultant outputs are listed below.
统计 string 中单词的数量。如果可选的参数 format 没有被指定,那么返回值是一个代表单词数量的整型数。如果指定了 format 参数,返回值将是一个数组,数组的内容则取决于 format 参数。format 的可能值和相应的输出结果如下所列。
For the purpose of this function, 'word' is defined as a locale dependent string containing alphabetic characters, which also may contain, but not start with "'" and "-" characters.
对于这个函数的目的来说,单词的定义是一个与区域设置相关的字符串。这个字符串可以包含字母字符,也可以包含 "'" 和 "-" 字符(但不能以这两个字符开始)。
*/
Parameters
string
- The string
- 字符串。
format
- Specify the return value of this function. The current supported values are:
- 指定函数的返回值。当前支持的值如下:
- 0 - returns the number of words found 返回单词数量
- 1 - returns an array containing all the words found inside the string 返回一个包含 string 中全部单词的数组
- 2 - returns an associative array, where the key is the numeric position of the word inside the string and the value is the actual word itself 返回关联数组。数组的键是单词在 string 中出现的数值位置,数组的值是这个单词
charlist
- A list of additional characters which will be considered as 'word'
- 附加的字符串列表,其中的字符将被视为单词的一部分。
Return Values
- Returns an array or an integer, depending on the format chosen.
- 返回一个数组或整型数,这取决于 format 参数的选择。
Changelog
- 5.1.0 Added the charlist parameter
Examples
<?php
/**
* Created by PhpStorm.
* User: zhangrongxiang
* Date: 2018/3/8
* Time: 下午9:48
*/
$str = "Hello fri3nd, you're
looking good today!";
//[0] => Hello
//[1] => fri
//[2] => nd
//[3] => you're
//[4] => looking
//[5] => good
//[6] => today
print_r( str_word_count( $str, 1 ) );
//[0] => Hello
//[6] => fri
//[10] => nd
//[14] => you're
//[28] => looking
//[45] => good
//[50] => today
print_r( str_word_count( $str, 2 ) );
//[0] => Hello
//[1] => fri3nd
//[2] => you're
//[3] => looking
//[4] => good
//[5] => today
print_r( str_word_count( $str, 1, 'àáãç3' ) );
//[0] => Hello
//[1] => fri3nd
//[2] => you're
//[3] => looking
//[4] => good
//[5] => today
//[6] => look123
//[7] => ing
$str = "Hello fri3nd, you're
looking good today!
look1234ing";
print_r( str_word_count( $str, 1, '0..3' ) );
See
All rights reserved
PHP之string之str_word_count()函数使用的更多相关文章
- php str_word_count()函数 语法
php str_word_count()函数 语法 作用:计算字符串中的单词数.大理石平规格 语法:str_word_count(string,return,char) 参数: 参数 描述 strin ...
- PHP str_word_count() 函数
实例 计算字符串 "Hello World!" 中的单词数: <?php高佣联盟 www.cgewang.comecho str_word_count("Hello ...
- OC与c混编实现Java的String的hashcode()函数
首先,我不愿意大家需要用到这篇文章里的代码,因为基本上你就是被坑了. 起因:我被Java后台人员坑了一把,他们要对请求的参数增加一个额外的字段,字段的用途是来校验其余的参数是否再传递过程中被篡改或因为 ...
- string类find函数返回值判定
string类find函数返回值判定 代码示例 #include<iostream> #include<cstring> using namespace std; int m ...
- C string.h 常用函数
参考:http://womendu.iteye.com/blog/1218155 http://blog.csdn.net/zccst/article/details/4294565 还有一些,忘记了 ...
- c++中string的常用函数说明
string可以说是是字符数组的升级版,使用更加啊方便,不容易出错.本文对string的常用函数进行简单介绍,做到会用即可. string中的常用函数分为四类,即赋值,添加,比较和删除. 一.赋值 1 ...
- C++ string类及其函数的讲解
文章来源于:http://www.cnblogs.com/hailexuexi/archive/2012/02/01/2334183.html C++中string是标准库中一种容器,相当于保存元素类 ...
- PHP之string之explode()函数使用
explode (PHP 4, PHP 5, PHP 7) explode - Split a string by string explode - 使用一个字符串分割另一个字符串 Descripti ...
- C++string类常用函数
C++string类常用函数 string类的构造函数:string(const char *s); //用c字符串s初始化string(int n,char c); //用n个字符c初 ...
随机推荐
- Java定时任务的实现
本例依据Java自身提供的接口实现,通过监听器(Listener)和定时器(Timer)定时执行某个任务(Task).专业的开源工具可参考Quartz:http://www.opensymphony. ...
- leetcode 合并两个有序数组
给定两个有序整数数组 nums1 和 nums2,将 nums2 合并到 nums1 中,使得 num1 成为一个有序数组. 说明: - 初始化 nums1 和 nums2 的元素数量分别为 m 和 ...
- python网络编程--进程(方法和通信),锁, 队列,生产者消费者模型
1.进程 正在进行的一个过程或者说一个任务.负责执行任务的是cpu 进程(Process: 是计算机中的程序关于某数据集合上的一次运行活动,是系统进行资源分配和调度的基本单位,是操作系统结构的基础.在 ...
- AI下载步骤
ai下载地址:https://www.adobe.com/cn/creativecloud/catalog/desktop.html?promoid=PTYTQ77P&mv=other 破解器 ...
- jzoj100029
陪审团制度历来是司法研究中的一个热议话题,由于陪审团的成员组成会对案件最终的结果产生巨大的影响,诉讼双方往往围绕陪审团由哪些人组成这一议题激烈争夺. 小 W 提出了一个甲乙双方互相制衡的陪审团成员挑选 ...
- 教你玩转XSS漏洞
什么是存储性XSS那? 通俗理解就是”xss“语句存在服务器上,可以一直被客户端浏览使用,所有登陆某一个存在”存储性xss“的页面的人,都会中招,可以是管理员,可以是普通的用户,所以他的危害是持续性的 ...
- 设置跨交换机VLAN
4台计算机,pc1 pc2 连接到交换机1的f1/1和f1/2.Pc3 pc4 连接到交换机2的f1/1和f1/2.pc1设置ip地址192.168.1.10,pc2 pc3 pc4设置ip地址192 ...
- linux进程查看及管理的工具
介绍Linux进程查看及管理的工具:pstree, ps, pidof, pgrep, top, htop, glance, pmap, vmstat, dstat, kill, pkill, jo ...
- unittest测试框架和测试报告的输出实例(一)
我们整个自动化才是报告的环节基本上分为三个部分: 1.测试用例的准备 2.测试用例的执行 3.测试报告的输出 1.测试用例的准备: 那我们就以搜孤网页做一个简单的用例: from selenium i ...
- 官宣,PyTorch 1.0 稳定版本现已推出
简评:快来一起快乐地学习吧. 随着 PyTorch 生态系统和社区继续为开发人员提供有趣的新项目和教育资源,今天(12 月 7日)在 NeurIPS 会议上发布了 PyTorch 1.0 稳定版.研究 ...