Random.class.php 515 B

1234567891011121314151617181920212223242526272829
  1. <?php
  2. namespace Tools {
  3. /**
  4. *
  5. */
  6. class Random {
  7. /**
  8. *
  9. */
  10. public static function getString( $length = 8 ) {
  11. $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  12. return substr(str_shuffle($chars),0,$length);
  13. }
  14. /**
  15. *
  16. */
  17. public static function getPlaceholder( $length, $idx ) {
  18. $suf = (string)$idx;
  19. $char = '$';
  20. return str_repeat($char, $length-strlen($suf)).$suf;
  21. }
  22. }
  23. }
  24. ?>