PHP Tutorials
PHP Forms
PHP Advanced
PHP OOP
The alphabet unit is a sequence of letters, such as "Hello world!".
In this article we will look at some commonly used methods to deceive ropes.
The PHP strlen()
function returns the length of the character unit.
Return the length of the string "Hello world!":
<?php
echo strlen("Hello world!"); // outputs 12
?>
The PHP function str_word_count()
counts the number of words in a character unit.
Count the number of word in the string "Hello world!":
<?php
echo str_word_count("Hello world!"); // outputs 2
?>
The PHP strrev()
function loosens the thread.
Reverse the string "Hello world!":
<?php
echo strrev("Hello world!"); // outputs !dlrow olleH
?>
The PHP strpos()
function searches for specific text within a character unit. When the same is found, the function restores the character of the original game character. If no match is found, it will return FALSE.
Search for the text "world" in the string "Hello world!":
<?php
echo strpos("Hello world!", "world"); // outputs 6
?>
Tip:The position of the first letter in a series is 0 (not 1).
The PHP str_replace()
function replaces characters with other characters in the series.
Replace the text "world" with "Dolly":
<?php
echo str_replace("world", "Dolly", "Hello world!"); // outputs Hello Dolly!
?>