"PHP Learning" PHP String functions

Source: Internet
Author: User

The string is a sequence of characters, such as "Hello world!". PHP String Functions

In this section, we will learn about commonly used string manipulation functions. PHP strlen () function

The strlen () function returns the length of a string, measured in characters.

The following example returns the length of the string "Hello world!": instance

<? PHP Echo strlen ("Hello world!" );? >

Running an instance

The output of the above code is: 12

Tip: strlen () is commonly used in loops and other functions when it is important to determine when a string ends. (for example, in a loop, we might need to stop looping after the last character of the string). PHP Strpos () function

The Strpos () function is used to retrieve the specified character or text within a string.

If a match is found, the first matching character position is returned. If no match is found, FALSE is returned.

The following example retrieves the text "World" in the string "Hello world!": instance

<? PHP Echo Strpos ("Hello world!", "World"); >

Running an instance

The output of the above code is: 6.

Tip: The position of the string "World" in the example above is 6. The reason for 6 (instead of 7) is that the position of the first character in the string is 0 instead of 1. Full PHP String Reference manual

For a complete string function reference manual, please visit our PHP String reference manual.

This manual provides a brief description and an example of each function!

"PHP Learning" PHP String functions

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.