utils.php 582 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. /**
  3. * Utility functions for WebBasics library.
  4. *
  5. * @author Taddeus Kroes
  6. * @date 05-10-2012
  7. * @since 0.2
  8. */
  9. namespace webbasics;
  10. /**
  11. * Camelize a string.
  12. *
  13. * @param string $string The string to camelize.
  14. * @param bool $upper Whether to make the first character uppercase (defaults to FALSE).
  15. * @return string The camelized string.
  16. */
  17. function camelize($string, $upper=false) {
  18. $camel = preg_replace_callback('/[_ -]([a-z])/', function($matches) {
  19. return strtoupper($matches[1]);
  20. }, $string);
  21. if ($upper)
  22. return ucfirst($camel);
  23. return $camel;
  24. }
  25. ?>