实例
	
	
		计算字符串 "Hello World!" 中的单词数:
	
	
		<?php
echo str_word_count("Hello world!");
?>
	
 
	定义和用法
	str_word_count() 函数计算字符串中的单词数。
	语法
	
		str_word_count(string,return,char)
	
 
	
		
			| 
				参数
			 | 
			
				描述
			 | 
		
		
			| 
				string
			 | 
			
				必需。规定要检查的字符串。
			 | 
		
		
			| 
				return
			 | 
			
				可选。规定 str_word_count() 函数的返回值。
				 
					可能的值:
				 
				
					- 
						0 - 默认。返回找到的单词的数目。
					
 
					- 
						1 - 返回包含字符串中的单词的数组。
					
 
					- 
						2 - 返回一个数组,其中的键名是单词在字符串中的位置,键值是实际的单词。
					
 
				 
			 | 
		
		
			| 
				char
			 | 
			
				可选。规定被认定为单词的特殊字符。
			 | 
		
	
	技术细节
	
		
			| 
				返回值:
			 | 
			
				返回一个数字或者一个数组,取决于所选择的 return 参数。
			 | 
		
		
			| 
				PHP 版本:
			 | 
			
				4.3.0+
			 | 
		
		
			| 
				更新日志:
			 | 
			
				在 PHP 5.1 中,新增了 char 参数。
			 | 
		
	
	更多实例
	
		实例 1
	
	
		返回包含字符串中的单词的数组:
	
	
		<?php
print_r(str_word_count("Hello world!",1));
?>
	
 
	
		实例 2
	
	
		返回一个数组,其中的键名是单词在字符串中的位置,键值是实际的单词:
	
	
		<?php
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,"&"));
?>