Return to substr_count_variation_001.phpt CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / standard / tests / strings |
1.1 misho 1: --TEST-- 2: Test substr_count() function (variation - 1) 3: --FILE-- 4: <?php 5: 6: echo "\n*** Testing possible variations ***\n"; 7: echo "-- 3rd or 4th arg as string --\n"; 8: $str = "this is a string"; 9: var_dump( substr_count($str, "t", "5") ); 10: var_dump( substr_count($str, "t", "5", "10") ); 11: var_dump( substr_count($str, "i", "5t") ); 12: var_dump( substr_count($str, "i", "5t", "10t") ); 13: 14: echo "\n-- 3rd or 4th arg as NULL --\n"; 15: var_dump( substr_count($str, "t", "") ); 16: var_dump( substr_count($str, "T", "") ); 17: var_dump( substr_count($str, "t", "", 15) ); 18: var_dump( substr_count($str, "I", NULL) ); 19: var_dump( substr_count($str, "i", NULL, 10) ); 20: 21: echo "\n-- overlapped substrings --\n"; 22: var_dump( substr_count("abcabcabcabcabc", "abca") ); 23: var_dump( substr_count("abcabcabcabcabc", "abca", 2) ); 24: 25: echo "\n-- complex strings containing other than 7-bit chars --\n"; 26: $str = chr(128).chr(129).chr(128).chr(256).chr(255).chr(254).chr(255); 27: var_dump(substr_count($str, chr(128))); 28: var_dump(substr_count($str, chr(255))); 29: var_dump(substr_count($str, chr(256))); 30: 31: echo "\n-- heredoc string --\n"; 32: $string = <<<EOD 33: abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 34: abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 35: acdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 36: acdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 37: abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 38: abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 39: abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 40: abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789 41: EOD; 42: var_dump(substr_count($string, "abcd")); 43: var_dump(substr_count($string, "1234")); 44: 45: echo "\n-- heredoc null string --\n"; 46: $str = <<<EOD 47: EOD; 48: var_dump(substr_count($str, "\0")); 49: var_dump(substr_count($str, "\x000")); 50: var_dump(substr_count($str, "0")); 51: 52: echo "Done\n"; 53: 54: ?> 55: --EXPECTF-- 56: *** Testing possible variations *** 57: -- 3rd or 4th arg as string -- 58: int(1) 59: int(1) 60: 61: Notice: A non well formed numeric value encountered in %s on line %d 62: int(2) 63: 64: Notice: A non well formed numeric value encountered in %s on line %d 65: 66: Notice: A non well formed numeric value encountered in %s on line %d 67: int(2) 68: 69: -- 3rd or 4th arg as NULL -- 70: 71: Warning: substr_count() expects parameter 3 to be long, string given %s on line %d 72: NULL 73: 74: Warning: substr_count() expects parameter 3 to be long, string given %s on line %d 75: NULL 76: 77: Warning: substr_count() expects parameter 3 to be long, string given %s on line %d 78: NULL 79: int(0) 80: int(2) 81: 82: -- overlapped substrings -- 83: int(2) 84: int(2) 85: 86: -- complex strings containing other than 7-bit chars -- 87: int(2) 88: int(2) 89: int(1) 90: 91: -- heredoc string -- 92: int(14) 93: int(16) 94: 95: -- heredoc null string -- 96: int(0) 97: int(0) 98: int(0) 99: Done