fork download
  1. <?php
  2. function convert($keyword, $debug = false) {
  3. $wResult = preg_match_all('/I(?=[[:upper:]][[:lower:]])|[[:upper:]]{2,}|[[:upper:]][[:lower:]]*|[[:lower:]]+|\d+|#/u', $keyword, $matches);
  4. if($debug){
  5. var_dump($matches);
  6. var_dump($matches[0]);
  7. var_dump(implode(' ',$matches[0]));
  8. }
  9. return implode(' ',$matches[0]);
  10. }
  11.  
  12. $search_keyword = array(
  13. "comeHEREtomorrow",
  14. "KissYouTODAY",
  15. "comeÜndeHere",
  16. "NEVERSAYIT",
  17. "2013willCome",
  18. "Before2013ends",
  19. "IKnowThat",
  20. "#whatiknow"
  21. );
  22. $need_keyword = array(
  23. "come HERE tomorrow",
  24. "Kiss You TODAY",
  25. "come Ünde Here",
  26. "NEVERSAYIT",
  27. "2013 will Come",
  28. "Before 2013 ends",
  29. "I Know That",
  30. "# whatiknow"
  31. );
  32.  
  33. $search_keyword2 = array(
  34. "Icons"
  35. , "WellIKnowThat"
  36. , "ITan"
  37. , "whirlwind"
  38. );
  39. $need_keyword2 = array(
  40. "Icons"
  41. , "Well I Know That"
  42. , "I Tan"
  43. , "whirlwind"
  44. );
  45. echo "Initial Cases:\n";
  46. foreach ($search_keyword as $key => $w) {
  47. $wExpected = $need_keyword[$key];
  48.  
  49. $wResult = convert($w);
  50.  
  51. $check = strcmp($wExpected, $wResult);
  52. $checkWord = ( $check == 0 ? "SUCCESS" : "FAILURE" );
  53.  
  54. echo "try $key,\t keyword: \"$w\" expected: \"$wExpected\" result: \"$wResult\" check: $check ($checkWord),\n";
  55. }
  56.  
  57.  
  58.  
  59. echo "\n\nSecondary Cases:\n";
  60. foreach ($search_keyword2 as $key => $w) {
  61. $wExpected = $need_keyword2[$key];
  62.  
  63. $wResult = convert($w);
  64.  
  65. $check = strcmp($wExpected, $wResult);
  66. $checkWord = ( $check == 0 ? "SUCCESS" : "FAILURE" );
  67.  
  68. echo "try $key,\t keyword: \"$w\" expected: \"$wExpected\" result: \"$wResult\" check: $check ($checkWord),\n";
  69. }
  70. ?>
Success #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
Initial Cases:
try 0,	 keyword: "comeHEREtomorrow" expected: "come HERE tomorrow" result: "come HERE tomorrow" check: 0 (SUCCESS),
try 1,	 keyword: "KissYouTODAY" expected: "Kiss You TODAY" result: "Kiss You TODAY" check: 0 (SUCCESS),
try 2,	 keyword: "comeÜndeHere" expected: "come Ünde Here" result: "come Ünde Here" check: 0 (SUCCESS),
try 3,	 keyword: "NEVERSAYIT" expected: "NEVERSAYIT" result: "NEVERSAYIT" check: 0 (SUCCESS),
try 4,	 keyword: "2013willCome" expected: "2013 will Come" result: "2013 will Come" check: 0 (SUCCESS),
try 5,	 keyword: "Before2013ends" expected: "Before 2013 ends" result: "Before 2013 ends" check: 0 (SUCCESS),
try 6,	 keyword: "IKnowThat" expected: "I Know That" result: "I Know That" check: 0 (SUCCESS),
try 7,	 keyword: "#whatiknow" expected: "# whatiknow" result: "# whatiknow" check: 0 (SUCCESS),


Secondary Cases:
try 0,	 keyword: "Icons" expected: "Icons" result: "Icons" check: 0 (SUCCESS),
try 1,	 keyword: "WellIKnowThat" expected: "Well I Know That" result: "Well I Know That" check: 0 (SUCCESS),
try 2,	 keyword: "ITan" expected: "I Tan" result: "I Tan" check: 0 (SUCCESS),
try 3,	 keyword: "whirlwind" expected: "whirlwind" result: "whirlwind" check: 0 (SUCCESS),