iconv_substr()
iconv_substr() — Cut out part of a string.
Built-in function of PHP 8.5. The manual lists it as available in PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
What it does
Cuts a portion of string specified by the offset and length parameters.
Signature
iconv_substr(string $string, int $offset, ?int $length = null, ?string $encoding = null): string|false
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $string | string | The original string. |
| $offset | int | If offset is non-negative, iconv_substr() cuts the portion out of string beginning at offset'th character, counting from zero. |
| $length | ?int | If length is given and is positive, the return value will contain at most length characters of the portion that begins at offset (depending on the length of string). |
| $encoding | ?string | If encoding parameter is omitted or null, string are assumed to be encoded in iconv.internal_encoding. |
Return value
Returns the portion of string specified by the offset and length parameters. If string is shorter than offset characters long, false will be returned. If string is exactly offset characters long, an empty string will be returned.
Example
The PHP manual ships no example for iconv_substr(); the signature and the parameter table above are the contract.
Changelog
| Version | Change |
|---|---|
| 8.0.0 | length and encoding are nullable now. |
| 7.0.11 | If string is equal to offset characters long, an empty string will be returned. Prior to this version, false was returned in this case. |
See also
substr(), mb_substr(), mb_strcut()
All PHP 8.5 built-in functions
Reference card built from the PHP manual page iconv_substr() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.