\Jawira\TheLostFunctions\str_bytes

str_bytes - Get string length in bytes.

Description

PHP has a 'function overloading' feature, it can be enabled using mbstring.func_overload option in php.ini. This option changes the behaviour of strlen, therefore this function is not reliable anymore to measure the size of a string in bytes.

Use str_bytes to get the size of a string in bytes. This function is not affected by 'function overloading'.

str_bytes(string $string): int

Parameters

string
The string being measured for length.

Return value

The size of the string in bytes.

Example

use function Jawira\TheLostFunctions\str_bytes;

str_bytes('hello'); // 5
str_bytes('Único'); // 6