markdown格式wiki文档

common.php 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * 下划线转驼峰(首字母大写)
  4. * 思路:
  5. * step1.原字符串转小写,原字符串中的分隔符用空格替换,在字符串开头加上分隔符
  6. * step2.将字符串中每个单词的首字母转换为大写,再去空格,去字符串首部附加的分隔符.
  7. */
  8. function camelize($uncamelized_words, $separator = '_')
  9. {
  10. $uncamelized_words = $separator . str_replace($separator, " ", strtolower($uncamelized_words));
  11. return ucwords(ltrim(str_replace(" ", "", ucwords($uncamelized_words)), $separator));
  12. }
  13. /**
  14. * 驼峰命名转下划线命名
  15. * 思路:
  16. * 小写和大写紧挨一起的地方,加上分隔符,然后全部转小写
  17. */
  18. function uncamelize($camelCaps, $separator = '_')
  19. {
  20. return strtolower(preg_replace('/([a-z])([A-Z])/', "$1" . $separator . "$2", $camelCaps));
  21. }
  22. /**
  23. * 防sql注入字符串转义
  24. * @param $content 要转义内容
  25. * @return array|string
  26. */
  27. function escapeString($content)
  28. {
  29. $pattern = "/(select[\s])|(insert[\s])|(update[\s])|(delete[\s])|(from[\s])|(where[\s])|(drop[\s])/i";
  30. if (is_array($content)) {
  31. foreach ($content as $key => $value) {
  32. $content[$key] = addslashes(trim($value));
  33. if (preg_match($pattern, $content[$key])) {
  34. echo $content[$key];
  35. $content[$key] = '';
  36. }
  37. }
  38. } else {
  39. $content = addslashes(trim($content));
  40. if (preg_match($pattern, $content)) {
  41. $content = '';
  42. }
  43. }
  44. return $content;
  45. }