Php searches for the number of words in a string

Source: Internet
Author: User
The str_word_count () function calculates the number of words in a string. syntax: the str_word_count (string, return, char) parameter description is required for the string to be checked. retur... the str_word_count () function calculates the number of words in a string.

Syntax:Str_word_count (string, return, char)

Parameter description

String is required, which specifies the string to be checked.

Return (optional) specifies the return value of the str_word_count () function.

Possible values: 0-default, returns the number of words found, 1-returns an array containing the words in the string, 2-returns an array, the key is the position of the word in the string, and the value is the actual word.

Return (optional) specifies the special character recognized as a word. the parameter is added in php 5.1 and the code is as follows:

$ Str = "hello world"; // define the string $ result = str_word_count ($ str); // search for the number of words echo $ result; // output result echo"
"; $ Result = str_word_count ($ str, 1); // returns the array print_r ($ result); // outputs the result array.


Article URL:

Reprint ^ at will, but please attach the tutorial address.

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.