如果我在PHP中有以下变量:
$Message='Hello, this is just test message';
如何获取其内容的字节大小?例如,要打印如下内容:
<p>Message size is 20KB</p>
发布于 2012-07-07 00:53:17
$start_memory = memory_get_usage();
$foo = "Some variable";
echo memory_get_usage() - $start_memory;
如果您正在使用任何类型的var,这是很好的。
发布于 2012-07-07 00:54:13
一个字符是一个字节,所以只需检查字符串长度。如果需要,以KB为单位除以1024 (为小数做好准备)。
<?php echo "Message size is ".strlen($Message)."B"; ?>
发布于 2012-07-07 00:52:07
https://stackoverflow.com/questions/11366412
复制相似问题