Problem:- How to Extract a Substring in PHP? If you want to extract part of a string starting at a particular place of a string. For example you want to extract 8 character is entered in input field.
Solution – Extract a Substring in PHP
<?php $username = 'hindialerts'; $username = substr($username, 0, 8); echo $username; ?>
How it Works
substr($string, $start, $length);
If $start and $length are positive substr() return $length characters in the string. for example we choose Hindialerts so by using substr($username, 0, 8) it return us the Hindiale only. We also can use negative value in this function just try it out and comment below if you got any error.
Leave a Reply