How to Extract a Substring in PHP?

How to Expose and Route to a Resource?
How to Expose and Route to a Resource?

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.

इसे भी पढ़े – 500 रुपए में सबसे सस्ता 4g फ़ोन

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *