starts-with.php 707 B

1234567891011121314151617181920212223242526
  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 starts with a given string
  15. *
  16. * @param string $haystack
  17. * @param string $needle
  18. * @return boolean
  19. */
  20. function startsWith($haystack, $needle) {
  21. $length = strlen($needle);
  22. return (substr($haystack, 0, $length) === $needle);
  23. }
  24. ?>