如何在PHP中获取变量内容的大小 [英] How to get the size of the content of a variable in PHP

查看:301
本文介绍了如何在PHP中获取变量内容的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在PHP中具有以下变量:

If I have the following variable in PHP:

$Message='Hello, this is just test message';

如何获取其内容的大小(以字节为单位)?例如,要打印以下内容:

How can I get the size of its content in bytes? For instance, to print something like:

<p>Message size is 20KB</p>

推荐答案

$start_memory = memory_get_usage();
$foo = "Some variable";
echo memory_get_usage() - $start_memory;

如果您正在使用任何类型的var,这很好.

This is good if you are working with any type of var.

这篇关于如何在PHP中获取变量内容的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆