Php str_word_count function example tutorial

Source: Internet
Author: User

Definition and usage
This str_word_count () function counts a string.

Syntax

str_word_count(string,return,char)
 
Parameter Description
String Required. Specified string check
Return Optional. Str_word_count () function of the returned value. Possible value: 0-default. Returns word count discovery 1-returns an array from string 2-returns an array in the key position is that the word string, and the value is the actual word
Char Optional. Special characters are considered as words. Note: this parameter is used in PHP 5.1.
Let's look at the instance.
<?phpecho str_word_count("Hello world!");?>
The output is 2.
 
Let's look at it again.
 
<?phpprint_r(str_word_count("Hello world!",1));?>
 
Result.
 
   
Array([0] => Hello[1] => world)
 
Check again.
 
<?phpprint_r(str_word_count("Hello world!",2));?>
 
Output result
 
Array([0] => Hello[6] => world)
 

Example 4
Str_word_count () does not match the coke parameter:

 

<?phpprint_r(str_word_count("Hello world & good morning!",1));print_r(str_word_count("Hello world & good morning!",1,"&"));?>
 
Output.
 
Array([0] => Hello[1] => world[2] => good[3] => morning)
Array([0] => Hello[1] => world[2] => &[3] => good[4] => morning)
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.