How to Extract A Substring from A Main String
The PHP substr() function is used to extract a Substring from a main string. Using this method you can grep a part of string by providing start and end point of number.
First see the below example:
1 2 3 4 5 6 7 8 9 | <?php $str = "Welcome PHP"; echo substr($str, 0, 7); // Output: Welcome echo substr($str, -3); // Output: PHP echo substr($str, 8, 3); // Output: PHP echo substr($str, 0, -4); // Output: Welcome echo substr($str, -8, 4); // Output: come echo substr($str, -11); // Output: Welcome PHP ?> |