Page 1 of 1

Is strlen = size in bytes also ?

Posted: Tue Jan 10, 2006 5:33 am
by anjanesh

Code: Select all

$contents = @file_get_contents($url);
$Total_Size = strlen($contents);
Does $Total_Size equal to the size of the file in bytes ?

Thanks

Posted: Tue Jan 10, 2006 5:41 am
by Maugrim_The_Reaper
Not that I'm aware...

filesize()?

Posted: Tue Jan 10, 2006 6:04 am
by anjanesh

Code: Select all

<?php
$filename = 'http://google.com';
echo $filename . ': ' . filesize($filename) . ' bytes';
?>
filesize doesnt seem to accept urls.
But strlen seems to be the answer according to one post.

Posted: Tue Jan 10, 2006 9:09 am
by feyd
strlen() is the byte count of the string given to it. filesize() cannot read remote url's because it requires file system level access to the file.

Posted: Tue Jan 10, 2006 10:09 am
by Weirdan
feyd wrote:strlen() is the byte count of the string given to it
... if it hasn't been overloaded by mbstring extension.

Posted: Tue Jan 10, 2006 10:18 am
by Maugrim_The_Reaper
Returns the length of the given string.
Maybe they should make it clearer? I honestly hadn't considered it before now... Its almost automatic to assume it means the number of letter - not bytes. Which makes it interesting given the attached comments in relation to UTF-8.

Well, you learn something new everyday :)