1--TEST-- 2str_word_count() 3--FILE-- 4<?php 5$str = "Hello friend, you're 6 looking good today!"; 7$b =& $str; 8var_dump(str_word_count($str, 1)); 9var_dump(str_word_count($str, 2)); 10var_dump(str_word_count($str)); 11 12try { 13 var_dump(str_word_count($str, 3)); 14} catch (\ValueError $e) { 15 echo $e->getMessage() . "\n"; 16} 17 18try { 19 var_dump(str_word_count($str, 123)); 20} catch (\ValueError $e) { 21 echo $e->getMessage() . "\n"; 22} 23 24try { 25 var_dump(str_word_count($str, -1)); 26} catch (\ValueError $e) { 27 echo $e->getMessage() . "\n"; 28} 29 30try { 31 var_dump(str_word_count($str, 999999999)); 32} catch (\ValueError $e) { 33 echo $e->getMessage() . "\n"; 34} 35 36var_dump($str); 37 38$str2 = "F0o B4r 1s bar foo"; 39var_dump(str_word_count($str2, 0, "04")); 40var_dump(str_word_count($str2, 0, "01")); 41var_dump(str_word_count($str2, 0, "014")); 42var_dump(str_word_count($str2, 0, "")); 43var_dump(str_word_count($str2, 1, "04")); 44var_dump(str_word_count($str2, 1, "01")); 45var_dump(str_word_count($str2, 1, "014")); 46var_dump(str_word_count($str2, 1, "")); 47var_dump(str_word_count($str2, 2, "04")); 48var_dump(str_word_count($str2, 2, "01")); 49var_dump(str_word_count($str2, 2, "014")); 50var_dump(str_word_count($str2, 2, "")); 51var_dump(str_word_count("foo'0 bar-0var", 2, "0")); 52var_dump(str_word_count("'foo'", 2)); 53var_dump(str_word_count("'foo'", 2, "'")); 54var_dump(str_word_count("-foo-", 2)); 55var_dump(str_word_count("-foo-", 2, "-")); 56 57?> 58 59DONE 60--EXPECT-- 61array(6) { 62 [0]=> 63 string(5) "Hello" 64 [1]=> 65 string(6) "friend" 66 [2]=> 67 string(6) "you're" 68 [3]=> 69 string(7) "looking" 70 [4]=> 71 string(4) "good" 72 [5]=> 73 string(5) "today" 74} 75array(6) { 76 [0]=> 77 string(5) "Hello" 78 [6]=> 79 string(6) "friend" 80 [14]=> 81 string(6) "you're" 82 [25]=> 83 string(7) "looking" 84 [42]=> 85 string(4) "good" 86 [47]=> 87 string(5) "today" 88} 89int(6) 90str_word_count(): Argument #2 ($format) must be a valid format value 91str_word_count(): Argument #2 ($format) must be a valid format value 92str_word_count(): Argument #2 ($format) must be a valid format value 93str_word_count(): Argument #2 ($format) must be a valid format value 94string(53) "Hello friend, you're 95 looking good today!" 96int(5) 97int(6) 98int(5) 99int(7) 100array(5) { 101 [0]=> 102 string(3) "F0o" 103 [1]=> 104 string(3) "B4r" 105 [2]=> 106 string(1) "s" 107 [3]=> 108 string(3) "bar" 109 [4]=> 110 string(3) "foo" 111} 112array(6) { 113 [0]=> 114 string(3) "F0o" 115 [1]=> 116 string(1) "B" 117 [2]=> 118 string(1) "r" 119 [3]=> 120 string(2) "1s" 121 [4]=> 122 string(3) "bar" 123 [5]=> 124 string(3) "foo" 125} 126array(5) { 127 [0]=> 128 string(3) "F0o" 129 [1]=> 130 string(3) "B4r" 131 [2]=> 132 string(2) "1s" 133 [3]=> 134 string(3) "bar" 135 [4]=> 136 string(3) "foo" 137} 138array(7) { 139 [0]=> 140 string(1) "F" 141 [1]=> 142 string(1) "o" 143 [2]=> 144 string(1) "B" 145 [3]=> 146 string(1) "r" 147 [4]=> 148 string(1) "s" 149 [5]=> 150 string(3) "bar" 151 [6]=> 152 string(3) "foo" 153} 154array(5) { 155 [0]=> 156 string(3) "F0o" 157 [4]=> 158 string(3) "B4r" 159 [9]=> 160 string(1) "s" 161 [11]=> 162 string(3) "bar" 163 [15]=> 164 string(3) "foo" 165} 166array(6) { 167 [0]=> 168 string(3) "F0o" 169 [4]=> 170 string(1) "B" 171 [6]=> 172 string(1) "r" 173 [8]=> 174 string(2) "1s" 175 [11]=> 176 string(3) "bar" 177 [15]=> 178 string(3) "foo" 179} 180array(5) { 181 [0]=> 182 string(3) "F0o" 183 [4]=> 184 string(3) "B4r" 185 [8]=> 186 string(2) "1s" 187 [11]=> 188 string(3) "bar" 189 [15]=> 190 string(3) "foo" 191} 192array(7) { 193 [0]=> 194 string(1) "F" 195 [2]=> 196 string(1) "o" 197 [4]=> 198 string(1) "B" 199 [6]=> 200 string(1) "r" 201 [9]=> 202 string(1) "s" 203 [11]=> 204 string(3) "bar" 205 [15]=> 206 string(3) "foo" 207} 208array(2) { 209 [0]=> 210 string(5) "foo'0" 211 [6]=> 212 string(8) "bar-0var" 213} 214array(1) { 215 [1]=> 216 string(4) "foo'" 217} 218array(1) { 219 [0]=> 220 string(5) "'foo'" 221} 222array(1) { 223 [1]=> 224 string(3) "foo" 225} 226array(1) { 227 [0]=> 228 string(5) "-foo-" 229} 230 231DONE 232