PHP substr() Function

The substr() function returns a part of a string.

substr() is used to get part of a string. The part of the string to be returned is specified as a range using the start and length arguments.

If start is a negative number and length is less than or equal to start, length becomes 0.
Syntax:

substr ( $string , $start , $length )

$string – Required. The input string. Must be one character or longer.
$start – Required. Specifies where to start in the string
$length – Optional. Specifies the length of the returned string. Default is to the end of the string.

Example

$date = 053111;
$month = substr($date, 0, 2);
$day = substr($date, 2, 2);
$year = substr($date, -2);

echo $year.”/”.$month.”/”.$day;

Output:
11/05/31

Posted in Php