jjacquay712 Posted July 23, 2010 Share Posted July 23, 2010 I am making a website that lets users submit data from their forms to our servers. I want to be able to measure the amount of data being passed to the php script from a form. I know that one character is a byte, so should I just use the strlen() function to count the characters and add the bytes? Is there a better way to do this? Thanks for the help. Link to comment https://forums.phpfreaks.com/topic/208692-calculating-size-of-data-kb-being-passed-from-a-form/ Share on other sites More sharing options...
jjacquay712 Posted July 23, 2010 Author Share Posted July 23, 2010 I figured out I can use the mb_strlen function. I went ahead and wrote a recursive function for those who might be interested. <?php function varsize($var) { $size = 0; if ( is_array($var) ) { foreach ( $var as $key => $value ) { if ( is_string($key) ) { $size += mb_strlen($key, '8bit'); } if ( is_array($value) ) { $size += varsize($value); } else { $size += mb_strlen((string)$value, '8bit'); } } } else { $size += mb_strlen((string)$var, '8bit'); } return $size; } echo varsize(array("test"=>array("recursive"=>"cool"))); ?> Link to comment https://forums.phpfreaks.com/topic/208692-calculating-size-of-data-kb-being-passed-from-a-form/#findComment-1090291 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.