Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use strlen () function and strpos () function in PHP

Shulou Source: shulou.com Published: 2022-06-01 13:13:39 10月06日 Update

This article is about how to use the strlen () function and the strpos () function in PHP. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

PHP string function

Strings are sequences of characters, such as "Hello world!".

PHP strlen () function

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

Note: this example returns the string "Hello world!" The length of. The output of the above code is: 12.

Tip: strlen () is often used for loops and other functions, and it's important to determine when a string ends.

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.

Note: this example retrieves the string "Hello world!" The text "world" in. The output of the above code is: 6.

Tip: the reason why the string "world" in the above example is 6 is that the position of the first character in the string is 0 instead of 1.

Thank you for reading! This is the end of the article on "how to use the strlen () function and strpos () function in PHP". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Tags: Character function string position code content instance text more comment article length prompt retrieval output good practical important sequence article Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Apple Shulou Technology NVidia Redmi