"PHP" / Говнокод #5216 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
function ini_size_to_bytes($value)
{
	$value = trim($value);
	$retval = intval($value);

	switch(strtolower($value[strlen($value) - 1]))
	{
		case 'g':
			$retval *= 1024;
			/* break missing intentionally */
		case 'm':
			$retval *= 1024;
			/* break missing intentionally */
		case 'k':
			$retval *= 1024;
			break;
	}

	return $retval;
}

vBulletin 4.0.3 (лицензионка, есть согласие на публикацию)

Запостил: Vitaly44 Vitaly44, (Updated )

Комментарии (11) RSS

  • function parse_size($size) {
      $unit = preg_replace('/[^bkmgtpezy]/i', '', $size); // Remove the non-unit characters from the size.
      $size = preg_replace('/[^0-9\.]/', '', $size); // Remove the non-numeric characters from the size.
      if ($unit) {
        // Find the position of the unit in the ordered string which is the power of magnitude to multiply a kilobyte by.
        return round($size * pow(DRUPAL_KILOBYTE, stripos('bkmgtpezy', $unit[0])));
      }
      else {
        return round($size);
      }
    }

    друпал. ой бл...
    Ответить
  • А мог бы кто-нибудь написать, как по-правильному выглядел бы код по парсингу строки: " 123g " ? -)
    Ответить
  • А ведь работает же просто case 'k': case 'm': case 'g': {}
    Ответить

Добавить комментарий

Из-за тебя ушел bormand, guest!

    А не использовать ли нам bbcode?


    8