← All built-ins / substr()

substr()

substr(...$args): string

Parameters

NameTypeDescription
$sstringinput string
$startintstart position (negative = from the end)
$lenintmaximum length; omitted = to the endoptional

Return value

The extracted substring.

Example

echo substr("HolyPHP", 0, 4), "
";
echo substr("HolyPHP", 4), "
";
echo substr("HolyPHP", -3), "
";
Holy
PHP
PHP

See also

strpos()str_replace()