PHP Strings: PHP String Functions Explained with Examples
1) PHP string function and explain it.
2) list any five-string function and explain in detail.
strlen
The strlen function is used to find the length of a string.
Let’s find the length of the string “Hello world!”.
echo strlen("Hello world!");strpos
strpos function is used to search for a string or character within a string.
Get Hug Growth’s stories in your inbox
Join Medium for free to get updates from this writer.
Let’s see if we can find the string “world” in our string.
echo strpos("Hello world!","world");strcmp
The strcmp() function compares two strings.
echo strcmp("Hello world!","Hello world!");trim
The trim() function removes whitespace and other predefined characters from both sides of a string.
$str = "Hello World!";
echo $str . "";
echo trim($str,"Hed!");ltrim
ltrim — Removes whitespace or other predefined characters from the left side of a string
$str = "Hello World!";
echo $str . "";
echo ltrim($str,"Hed!");rtrim
rtrim — Removes whitespace or other predefined characters from the right side of a string
$str = "Hello World!";
echo $str . "";
echo rtrim($str,"Hed!");ucfirst
The ucfirst() function converts the first character of a string to uppercase.
echo ucfirst("hello world!");ucwords
The ucwords() function converts the first character of each word in a string to uppercase.
echo ucwords("hello world");strtolower
The strtolower() function converts a string to lowercase.
echo strtolower("Hello WORLD.");strtoupper
The strtoupper() function converts a string to uppercase.
echo strtoupper("Hello WORLD!");

