iconv_strlen()
iconv_strlen() — Returns the character count of 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
In contrast to strlen(), iconv_strlen() counts the occurrences of characters in the given byte sequence string on the basis of the specified character set, the result of which is not necessarily identical to the length of the string in bytes.
Signature
iconv_strlen(string $string, ?string $encoding = null): int|false
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $string | string | The string. |
| $encoding | ?string | If encoding parameter is omitted or null, string is assumed to be encoded in iconv.internal_encoding. |
Return value
Returns the character count of string, as an integer, or false if an error occurs during the encoding.
Example
The PHP manual ships no example for iconv_strlen(); the signature and the parameter table above are the contract.
Changelog
| Version | Change |
|---|---|
| 8.0.0 | encoding is nullable now. |
See also
All PHP 8.5 built-in functions
Reference card built from the PHP manual page iconv_strlen() (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.