iconv_substr

(PHP 5, PHP 7, PHP 8)

iconv_substrCut out part of a string

Description

iconv_substr(
    string $string,
    int $offset,
    ?int $length = null,
    ?string $encoding = null
): string|false

Cuts a portion of string specified by the offset and length parameters.

Parameters

string

The original string.

offset

If offset is non-negative, iconv_substr() cuts the portion out of string beginning at offset'th character, counting from zero.

If offset is negative, iconv_substr() cuts out the portion beginning at the position, offset characters away from the end of string.

length

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).

If negative length is passed, iconv_substr() cuts the portion out of string from the offset'th character up to the character that is length characters away from the end of the string. In case offset is also negative, the start position is calculated beforehand according to the rule explained above.

encoding

If encoding parameter is omitted or null, string are assumed to be encoded in iconv.internal_encoding.

Note that offset and length parameters are always deemed to represent offsets that are calculated on the basis of the character set determined by encoding, whilst the counterpart substr() always takes these for byte offsets.

Return Values

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.

Changelog

Version Description
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

Here you can write a comment


Please enter at least 10 characters.
Loading... Please wait.
* Pflichtangabe
There are no comments available yet.

PHP cURL Tutorial: Using cURL to Make HTTP Requests

cURL is a powerful PHP extension that allows you to communicate with different servers using various protocols, including HTTP, HTTPS, FTP, and more. ...

TheMax

Autor : TheMax
Category: PHP-Tutorials

Midjourney Tutorial - Instructions for beginners

There is an informative video about Midjourney, the tool for creating digital images using artificial intelligence, entitled "Midjourney tutorial in German - instructions for beginners" ...

Mike94

Autor : Mike94
Category: KI Tutorials

Basics of views in MySQL

Views in a MySQL database offer the option of creating a virtual table based on the result of an SQL query. This virtual table can be queried like a normal table without changing the underlying data. ...

admin

Autor : admin
Category: mySQL-Tutorials

Publish a tutorial

Share your knowledge with other developers worldwide

Share your knowledge with other developers worldwide

You are a professional in your field and want to share your knowledge, then sign up now and share it with our PHP community

learn more

Publish a tutorial