When many characters are written together in sequence, they create a string. For example, Rahul is a string. It’s made up of r, a, h, u, l characters. One string can be composed of many types of elements. You can see it as an example.
Numbers – You can take any number from 0 to 9 in a string.
Letters – A string may be composed of small letters (a – z) or capital letters (A – Z).
It’s very easy to create strings in PHP and work with them. PHP also provides some built in functions to work with strings. Let us now see how you can create strings in PHP.
You create strings in PHP just like a normal variable. Its simple syntax is being given below. You can type the string in double quotes or in single quotes.
$string-name = "string";
PHP Strings Function
PHP provides you with more than 100 built in string functions. Some of these functions are being explained by example below.
strlen()
You can get the length of any string by using this string function. This function returns the same number of charecters you have in the string. This number includes spaces too. It has been explained through an example.
<?php echo strlen("Hello world!"); ?> Output 12
Strrev()
With this function you can show any string value in reverse order. This is being explained by the example below.
<?php $val = "rahul"; echo strrev($val); ?> Output luhar