A string is a cycle of characters, like “Hello India!”
Length of a String:-
The PHP strlen() returns the length of a string.
Example:-
<?php
echo strlen(“Hello India!”); // outputs 12
?>
Words Count in a String:-
The PHP str_word_count() counts the number of words in a string.
Example:-
<?php
echo str_word_count(“Hello India Today!”); // outputs 3
?>
Reverse a String:-
The PHP strrev() reverses a string.
Example:-
<?php
echo strrev(“Hello India!”); // outputs !aidni olleH
?>
Search Specific Text within a String:-
The PHP strpos() searches for a specific text within a string. If a match is found, this returns the character location of the first match. If no match is found, it will return FALSE.
Example:-
<?php
echo strpos(“Hello India!”, “India”); // outputs 6
?>
Replace Text within a String:-
The PHP str_replace() replaces some typeset with some other typeset in a string.
Example:-
<?php
echo str_replace(“India”, “world”, “Hello India!”); // outputs Hello world!
?>

Categories: PHP

0 thoughts on “PHP Strings”

Leave a Reply