filter.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * ZeroBin
  4. *
  5. * a zero-knowledge paste bin
  6. *
  7. * @link http://sebsauvage.net/wiki/doku.php?id=php:zerobin
  8. * @copyright 2012 Sébastien SAUVAGE (sebsauvage.net)
  9. * @license http://www.opensource.org/licenses/zlib-license.php The zlib/libpng License
  10. * @version 0.19
  11. */
  12. /**
  13. * filter
  14. *
  15. * Provides data filtering functions.
  16. */
  17. class filter
  18. {
  19. /**
  20. * strips slashes deeply
  21. *
  22. * @access public
  23. * @static
  24. * @param mixed $value
  25. * @return mixed
  26. */
  27. public static function stripslashes_deep($value)
  28. {
  29. return is_array($value) ?
  30. array_map('filter::stripslashes_deep', $value) :
  31. stripslashes($value);
  32. }
  33. /**
  34. * format a given number of bytes
  35. *
  36. * @access public
  37. * @static
  38. * @param int $size
  39. * @return string
  40. */
  41. public static function size_humanreadable($size)
  42. {
  43. $iec = array('B', 'kiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB');
  44. $i = 0;
  45. while ( ( $size / 1024 ) >= 1 ) {
  46. $size = $size / 1024;
  47. $i++;
  48. }
  49. return number_format($size, ($i ? 2 : 0), '.', ' ') . ' ' . $iec[$i];
  50. }
  51. }