1
0

endswith.php 747 B

1234567891011121314151617181920212223242526272829
  1. <?php
  2. /**
  3. * dolphin. Collection of useful PHP skeletons.
  4. * Copyright (C) 2019 Johannes 'Banana' Keßler
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the COMMON DEVELOPMENT AND DISTRIBUTION LICENSE
  8. *
  9. * You should have received a copy of the
  10. * COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
  11. * along with this program. If not, see http://www.sun.com/cddl/cddl.html
  12. */
  13. /**
  14. * check if a string ends with a given string
  15. *
  16. * @param string $haystack
  17. * @param string $needle
  18. * @return boolean
  19. */
  20. static function endsWith($haystack, $needle) {
  21. $length = strlen($needle);
  22. if ($length == 0) {
  23. return true;
  24. }
  25. return (substr($haystack, -$length) === $needle);
  26. }
  27. ?>