PHP substr() function Last Updated : 22 Jun, 2023 Comments Improve Suggest changes Like Article Like Report The substr() is a built-in function in PHP that is used to extract a part of string. Syntax: substr(string_name, start_position, string_length_to_cut) Parameters: The substr() function allows 3 parameters or arguments out of which two are mandatory and one is optional. string_name: In this parameter, we pass the original string or the string that needs to cut or modified. This is a mandatory parameter start_position: This refers to the position of the original string from where the part needs to be extracted. In this, we pass an integer. If the integer is positive it refers to the start of the position in the string from the beginning. If the integer is negative then it refers to the start of the position from the end of the string. This is also a mandatory parameter. string_length_to_cut: This parameter is optional and of integer type. This refers to the length of the part of the string that needs to be cut from the original string. If the integer is positive, it refers to start from start_position and extract length from the beginning. If the integer is negative then it refers to start from start_position and extract length from the end of the string. If this parameter is not passed, then the substr() function will return the string starting from start_position till the end of string. Return Type: Returns the extracted part of the string if successful otherwise FALSE or an empty string on failure. Below is a program to illustrate working of substr() in PHP: PHP <?php // PHP program to illustrate substr() function Substring($str){ $len = strlen($str); echo substr($str, 8), "\n"; echo substr($str, 5, $len), "\n"; echo substr($str, -5, 10), "\n"; echo substr($str,-8, -5), "\n"; } // Driver Code $str="GeeksforGeeks"; Substring($str); ?> Output: Geeks forGeeks Geeks for Comment More info C chinmoy lenka Follow Improve Article Tags : Misc Web Technologies PHP Functions PHP-string PHP-function +2 More Explore PHP Tutorial 8 min read BasicsPHP Syntax 4 min read PHP Variables 5 min read PHP | Functions 8 min read PHP Loops 4 min read ArrayPHP Arrays 5 min read PHP Associative Arrays 4 min read Multidimensional arrays in PHP 5 min read Sorting Arrays in PHP 4 min read OOPs & InterfacesPHP Classes 2 min read PHP | Constructors and Destructors 5 min read PHP Access Modifiers 4 min read Multiple Inheritance in PHP 4 min read MySQL DatabasePHP | MySQL Database Introduction 4 min read PHP Database connection 2 min read PHP | MySQL ( Creating Database ) 3 min read PHP | MySQL ( Creating Table ) 3 min read PHP AdvancePHP Superglobals 6 min read PHP | Regular Expressions 12 min read PHP Form Handling 4 min read PHP File Handling 4 min read PHP | Uploading File 3 min read PHP Cookies 9 min read PHP | Sessions 7 min read Like