substr() functin in PHP

substr() function is widely used to solve problem related to content in php.
For example : If you want to get specific word from sentence  so you can do it through substr and many other problem can be solved through substr.
here is syntax of substr

substr(String , Start , Length);


  • String:  String is word,sentence or paragraph which you want use for substr function
  • start :  Starting point for substr function from which it start geting characher.If word is welcome here if start parameter is 0 then it start from w , if is 1 then it start from e and onwards . 
  • Length : how many characters you want to extract ,you have to mention lenght in function . Suppose word is welcome If you write 1 there it will return only w , if 2 then we or 3 then it will return wel and onwards.
You will more cleared after running this program

<?php
               $string = "Welcome to my Blog"; // I want to extract Welcome
               $new_string = substr($string,0,7);
               echo $new_string;
?>

Hope You understand Thank You for reading.

No comments:

Post a Comment