Is strlen = size in bytes also ?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Is strlen = size in bytes also ?

Post 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
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

Not that I'm aware...

filesize()?
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

feyd wrote:strlen() is the byte count of the string given to it
... if it hasn't been overloaded by mbstring extension.
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post 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 :)
Post Reply