php获取字节,从php.ini中的简写字节符号获取字节值

The paragraph you linked to结束:

You may not use these shorthand notations outside of PHP.ini,instead

use an integer value of bytes. See 07001 for an

example on how to convert these values.

这会导致你这样的东西(我稍稍修改):

function return_bytes($val)

{

$val = trim($val);

$last = strtolower($val[strlen($val)-1]);

$val = substr($val,-1); // necessary since PHP 7.1; otherwise optional

switch($last) {

// The 'G' modifier is available since PHP 5.1.0

case 'g':

$val *= 1024;

case 'm':

$val *= 1024;

case 'k':

$val *= 1024;

}

return $val;

}

echo return_bytes("3M");

// Output: 3145728

没有内置函数执行此任务;回想一下,真正的INI设置是在PHP内部设计的. PHP源使用与上述类似的功能.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值