Reputation: 27
I want to know the memory capacity of the single character in php.
Please anyone give me the code or reference link to get the memory of a character.
Is there any predefined function for calculating the memory of a character as like
strlen();
I have the sample code for calculating the bandwidth of the webpage
This is the sample code
$speed = 10;
ob_start();
include(filename.php);
$now = time();
foreach(str_split(ob_get_clean(), $speed*1024) as $chunk)
{
echo $chunk;
flush();
$now++;
while($now > time())
{
usleep(1000000);
}
}
From this i can get the number of character by using the ob_get_lenght().
If i know the memory of a character then i can find the bandwidth for the webpage
Upvotes: 0
Views: 845
Reputation: 41958
In PHP a character always maps one-to-one on a single octet, ie. a byte. As such strlen
correctly returns the number of bytes in a single string - although it might consume more memory because of internal representation (trailing zero or length integer).
To support multibyte notations you need to use the mbstring functions.
Upvotes: 4
Reputation: 2406
See http://www.php.net/manual/en/language.types.string.php. A character is the same as a byte, according to that page.
Also, a character can be multiple bytes (multibyte), depending on the encoding. From my experience, you would need to have the mbstring extension enabled for that. If you don't know if your characters are multiple bytes, then each character is probably one byte.
Upvotes: 0