php tutorial - PHP substr Function - php programming - learn php - php code - php script



  • The substr function is used for returning the part of string.

php scripts Syntax :

substr(string,start,length);
click below button to copy the code. php tutorial - team

  • The substr string function contains three basic parameters. The first parameter of the string defines original string content.
  • Second parameter is defining the position of the starting point.
  • Third parameter is the number of characters to be returned.

Sample Code in php : sample php program

<!DOCTYPE html>
<html>
    <body>
        <?php
            $var1 = 'Welcome to wikitechy technical forum';
            echo substr($var1,0,20).'...';
        ?>
    </body>
</html>
click below button to copy the code. php tutorial - team

php programmer Code Explanation :

Code Explanation for substr Function In PHP

  1. In this example the “$var1” contains a set of character (or) string.
  2. In this echo statement we call the substr string function that contains three parameters: the first parameter($var1) defines given string and the second parameter (0) as the starting positon of the string and the third parameter (20) as end of string position.

php development Sample Output :

output for substr Function In PHP

  1. Output is “Welcome to wikitechy technical forum” will be sub stringed using substr function where the string function has the initial value as “0” and end position of the string as “20” , so that content ( Welcome to wikitechy) will only be displayed in this output window as shown.


Related Searches to php substr function