PHP String
PHP String-
PHP String: A string is a sequence of characters like “Welcome!”
Get The Length of a String
The PHP strlen () function returns the length of a string.

Example
|
1 2 3 |
<?php echo strlen("Welcome my Tutorial Scan!"); ?> |
output:
|
1 |
25 |
Count The Number of Words in a String
The PHP str_word_count() function counts the number of words in a string:
Example
|
1 2 3 |
<?php echo str_word_count("Welcome my Tutorial Scan!"); ?> |
Output:
|
1 |
4 |
Reverse a String
The PHP strrev() function reverses a string:
Example
|
1 2 3 |
<?php echo strrev("Hello Tutorial!"); ?> |
Output:
|
1 |
!lairotuT olleH. |
The Search For a Specific Text Within a PHP String
The PHP strpos() function searches for a specific text( which you want to write text) within a string.
If a match is found, the function returns the character position of the first match. If no match is found, it will return FALSE.
Example
|
1 2 3 |
<?php echo strpos("Hello world!", "world"); ?> |
Output:
|
1 |
6 |
Replace Text Within a String
In PHP str_replace() function is used to replaces some characters with some other characters in a string.
Example
|
1 2 3 |
<?php echo str_replace("world", "India", "Hello world!"); ?> |
Output:
|
1 |
Hello India! |
Resource
PHP.net