Strings.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /*
  3. * To change this license header, choose License Headers in Project Properties.
  4. * To change this template file, choose Tools | Templates
  5. * and open the template in the editor.
  6. */
  7. /**
  8. * Description of Str
  9. *
  10. * @author jgao
  11. */
  12. class Strings {
  13. //put your code here
  14. /**
  15. * 字符串包含判定
  16. * @param type $string 完整字符串
  17. * @param type $sub 子串
  18. * @return type
  19. */
  20. static function contains($str, $sub){
  21. return strpos($str, $sub) !== false;
  22. }
  23. /**
  24. * 字符串分割
  25. * @param type $str
  26. * @param type $char
  27. * @return type
  28. */
  29. static function split($str,$char=','){
  30. if($str == ""){
  31. return array();
  32. }
  33. $strArr = explode($char, $str);
  34. return $strArr;
  35. }
  36. /**
  37. * 字符串分割为二进制数据
  38. * @param type $str
  39. * @param type $char
  40. * @return type
  41. */
  42. static function splitRaw($str,$char=','){
  43. $rawArr = array();
  44. if($str != ""){
  45. $strArr = self::split($str, $char);
  46. foreach($strArr as $item){
  47. $rawArr[] = (real)$item;
  48. }
  49. }
  50. return $rawArr;
  51. }
  52. }