The only operators that can operate on strings are . and .= which are for concatenation and concatenation assignment respectively. Strings can be treated as arrays i.e., individual characters can be accessed using the index values. The index value begins with zero. A character at index i can be retrieved as $str[i]. An example is given below:
1 2 3 4 |
<?php $str1 = "master"; print($str1[2]); ?> |
The print statement in the above code prints ‘s’.
There are several predefined functions to manipulate strings. Some of them are listed below:
Leave a Reply