substr()


string substr ( string $string, int $start [ , int $length ] )

Description

substr() returns the portion of string specified by the start and length parameters

※ available F/W version : all

Parameters

Return values

Returns the extracted part of string on success, FALSE on failure.

Example

<?php
$str = "abcdef";
$ret = substr($str, 2); echo "$ret\r\n";       // OUTPUT: cdef
$ret = substr($str, -1); echo "$ret\r\n";      // OUTPUT: f
$ret = substr($str, -2); echo "$ret\r\n";      // OUTPUT: ef
$ret = substr($str, 2, 3); echo "$ret\r\n";    // OUTPUT: cde
$ret = substr($str, -3, 1); echo "$ret\r\n";   // OUTPUT: d
$ret = substr($str, 0, -1); echo "$ret\r\n";   // OUTPUT: abcde
$ret = substr($str, 2, -1); echo "$ret\r\n";   // OUTPUT: cde
$ret = substr($str, 4, -4); echo "$ret\r\n";   // OUTPUT: 0
$ret = substr($str, -3, -1); echo "$ret\r\n";  // OUTPUT: de

$ret = substr($str, 9); 
if($ret === FALSE) echo "returned FALSE\r\n";  // OUTPUT: returned FALSE
?>

See also

str_repeat() / strpos() / str_replace() / substr_replace()

Remarks

This function is identical to the PHP group’s substr() function.