StringUtil.php 797 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace PhpZip\Util;
  3. /**
  4. * String Util.
  5. *
  6. * @internal
  7. */
  8. final class StringUtil
  9. {
  10. /**
  11. * @param string $haystack
  12. * @param string $needle
  13. *
  14. * @return bool
  15. */
  16. public static function endsWith($haystack, $needle)
  17. {
  18. $length = \strlen($needle);
  19. if ($length === 0) {
  20. return true;
  21. }
  22. return substr($haystack, -$length) === $needle;
  23. }
  24. /**
  25. * @param string $string
  26. *
  27. * @return bool
  28. */
  29. public static function isBinary($string)
  30. {
  31. return strpos($string, "\0") !== false;
  32. }
  33. /**
  34. * @param string $name
  35. *
  36. * @return bool
  37. */
  38. public static function isASCII($name)
  39. {
  40. return preg_match('~[^\x20-\x7e]~', (string) $name) === 0;
  41. }
  42. }