PHP String Functions
A string is a sequence of characters, like "Hello world!".
PHP String Functions
In this chapter we will look at some commonly used functions to manipulate strings.
The PHP strlen() function
The strlen() function returns the length of a string, in characters.
The example below returns the length of the string "Hello world!":
Example
<html>
<body>
<?php
echo strlen("Hello world!");
?>
</body>
</html>
<body>
<?php
echo strlen("Hello world!");
?>
</body>
</html>
The PHP strpos() function
The strpos() function is used to search for a specified character or text within a string.
If a match is found, it will return the character position of the first match. If no match is found, it will return FALSE.
The example below searches for the text "world" in the string "Hello world!":
Example
<html>
<body>
<?php
echo strpos("Hello world!","world");
?>
</body>
</html>
<body>
<?php
echo strpos("Hello world!","world");
?>
</body>
</html>
0 comments:
Post a Comment