Home > Article > Backend Development > 9 PHP string functions
PHP strlen() function
strlen() function returns the length of a string, in characters.
<code><span><span><?php</span><span>echo</span> strlen(<span>"Hello world!"</span>); <span>?></span></span> 输出:12</code>
PHP strpos() function
strpos() function is used to retrieve specified characters or text within a string.
If a match is found, the first matching character position is returned. If no match is found, FALSE will be returned.
<code><span><span><?php</span><span>echo</span> strpos(<span>"Hello world!"</span>,<span>"world"</span>); <span>?></span></span></code>
The output of the above code is: 6.
Tips: The position of the string "world" in the above example is 6. The reason for 6 (rather than 7) is that the first character in the string is at position 0 instead of 1.
Copyright Statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission.
The above has introduced 9 PHP string functions, including relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.