Skip to content

Instantly share code, notes, and snippets.

@SoftCreatR
Created September 13, 2014 18:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SoftCreatR/21cf88cb3ba525fd2a40 to your computer and use it in GitHub Desktop.
Save SoftCreatR/21cf88cb3ba525fd2a40 to your computer and use it in GitHub Desktop.
<?php
namespace wcf\util;
/**
* Extended math-related functions.
*
* @author Sascha Greuel <sascha@softcreatr.de>
* @copyright Sascha Greuel
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @package com.woltlab.wcf
* @subpackage util
* @category Community Framework
*/
final class MathUtilExt {
/**
* Converts a php.ini directive (e.g. post_max_size)
* into an integer (Bytes)
*
* @param string $iniValue
* @return integer
*/
public function toBytes($iniValue) {
$iniValue = StringUtil::trim($iniValue);
$s = array(
'g' => 1 << 30,
'm' => 1 << 20,
'k' => 1 << 10
);
return intval($iniValue) * ($s[mb_strtolower(substr($iniValue, -1))] ?: 1);
}
private function __construct() { }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment