PHP str_word_count() 函数
PHP 教程
· 2019-01-30 06:28:08
实例
计算字符串 "Hello World!" 中的单词数:
<?php
echo str_word_count("Hello world!");
?>
echo str_word_count("Hello world!");
?>
定义和用法
str_word_count() 函数计算字符串中的单词数。
语法
str_word_count(string,return,char)
| 参数 | 描述 |
|---|---|
| string | 必需。规定要检查的字符串。 |
| return | 可选。规定 str_word_count() 函数的返回值。 可能的值:
|
| char | 可选。规定被认定为单词的特殊字符。 |
技术细节
| 返回值: | 返回一个数字或者一个数组,取决于所选择的 return 参数。 |
|---|---|
| PHP 版本: | 4.3.0+ |
| 更新日志: | 在 PHP 5.1 中,新增了 char 参数。 |
更多实例
实例 1
返回包含字符串中的单词的数组:
<?php
print_r(str_word_count("Hello world!",1));
?>
print_r(str_word_count("Hello world!",1));
?>
实例 2
返回一个数组,其中的键名是单词在字符串中的位置,键值是实际的单词:
<?php
print_r(str_word_count("Hello world!",2));
?>
print_r(str_word_count("Hello world!",2));
?>
实例 3
没有 char 参数和有 char 参数:
<?php
print_r(str_word_count("Hello world & good morning!",1));
print_r(str_word_count("Hello world & good morning!",1,"&"));
?>
print_r(str_word_count("Hello world & good morning!",1));
print_r(str_word_count("Hello world & good morning!",1,"&"));
?>
点击查看所有 PHP 教程 文章: https://www.codercto.com/courses/l/5.html
Python学习手册(第4版)
[美] Mark Lutz / 李军、刘红伟 / 机械工业出版社 / 2011-4 / 119.00元
Google和YouTube由于Python的高可适应性、易于维护以及适合于快速开发而采用它。如果你想要编写高质量、高效的并且易于与其他语言和工具集成的代码,《Python学习手册:第4 版》将帮助你使用Python快速实现这一点,不管你是编程新手还是Python初学者。本书是易于掌握和自学的教程,根据作者Python专家Mark Lutz的著名培训课程编写而成。 《Python学习手册:第......一起来看看 《Python学习手册(第4版)》 这本书的介绍吧!