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

Latest Article

Blog

PHP Magic Methods

__get()/__set() – These are magic getters and setters for getting and putting values for class properties created dynamically. __isset() – This magic method will be invoked automatically while checking whether a required overloaded property is Read more…

Blog

WordPress Upgrade

The WordPress upgrade released time to time. We provide a WordPress upgrade, content management and maintenance services at affordable price. WordPress upgrade fixes bugs, runs cleaner, faster, and is more secure and stable. We will Read more…

Blog

Magento 2 Upload image in product

If you are trying to upload image on respective product by script then below code will help you to solve this issue. by this code you can set product thumbnail, small and large image. $objectManager Read more…