PHP substr() function
This function is used to return a part of a string or substring from a string, starting from a given position.
Syntax
substr(string_name, start_position, substring_length)
string_name - It is the required parameter. It should be string datatype.
start_position - It is also a required parameter.
It specifies the string position and always be an integer value.
substring_length - It contains length of string. If it is positive, the returned string contains length characters from the beginning
and if it is negative, the returned string contains length characters from the end of the string.
Example
<?php
$str = 'Welcome to India!';
$substr1 = substr($str, 0);
echo $substr1.'<br/>';
$substr2 = substr($str, 0 , 7);
echo $substr2.'<br/>';
$substr3 = substr($str, 7, 9);
echo $substr3;
?>
Output :
India!Welcome
to India
Related PHP Functions
PHP array_reverse() functionPHP array_diff() function
PHP array_key_exists() function
PHP array_push() function
PHP array_search() function
PHP class_exists() function
PHP curl_setopt() function
PHP die() function
PHP dirname() function
PHP each() function
PHP explode() function
PHP file_exists() function
PHP function_exists() function
PHP getenv() function
PHP is_readable() function
PHP ksort() function
PHP mkdir() function
PHP ob_start() function
PHP parse_url() function
PHP str_repeat() function
PHP substr() function