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.
PHP String
Example

<?php
echo strlen("Welcome my Tutorial Scan!"); 
?>

output:

25

Count The Number of Words in a String
The PHP str_word_count() function counts the number of words in a string:

Example

<?php
echo str_word_count("Welcome my Tutorial Scan!");
?>

Output:

4

Reverse a String
The PHP strrev() function reverses a string:

Example

<?php
echo strrev("Hello Tutorial!"); 
?>

Output:

!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

<?php
echo strpos("Hello world!", "world"); 
?>

Output:

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

<?php
echo str_replace("world", "India", "Hello world!"); 
?>

Output:

Hello India!

 

Resource
PHP.net