2 /* Prototype : proto int strcspn(string str, string mask [, int start [, int len]])
3 * Description: Finds length of initial segment consisting entirely of characters not found in mask.
4 If start or/and length is provided works like strcspn(substr($s,$start,$len),$bad_chars)
5 * Source code: ext/standard/string.c
6 * Alias to functions: none
10 * Testing strcspn() : with varying start and default len arguments
13 echo "*** Testing strcspn() : with different start and default len values ***\n";
15 // initialing required variables
16 // initialing required variables
22 "hello\tworld\nhello\nworld\n",
23 'hello\tworld\nhello\nworld\n',
24 "1234hello45world\t123",
25 '1234hello45world\t123',
29 chr(0)."hello\0world".chr(0),
30 chr(0).'hello\0world'.chr(0),
31 "hello".chr(0)."world",
32 'hello'.chr(0).'world',
33 "hello\0\100\xaaaworld",
34 'hello\0\100\xaaaworld'
37 // defining array of mask strings
51 //defining array of start values
58 2147483647, // max positive integer
59 -2147483648, // min negative integer
63 // loop through each element of the arrays for str,mask and start arguments
65 foreach($strings as $str) {
66 echo "\n-- Iteration $count --\n";
67 foreach($mask_array as $mask) {
68 foreach($start_array as $start) {
69 var_dump( strcspn($str,$mask,$start) );