Annotation of embedaddon/php/ext/standard/tests/strings/strcspn_variation9.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test strcspn() function : usage variations - different strings with default start and len args
3: --FILE--
4: <?php
5: /* Prototype : proto int strcspn(string str, string mask [, int start [, int len]])
6: * Description: Finds length of initial segment consisting entirely of characters not found in mask.
7: If start or/and length is provided works like strcspn(substr($s,$start,$len),$bad_chars)
8: * Source code: ext/standard/string.c
9: * Alias to functions: none
10: */
11:
12: /*
13: * Testing strcspn() : with different strings as str argument and default start and len args
14: */
15:
16: echo "*** Testing strcspn() : with different str and default start and len args ***\n";
17:
18: // initialing required variables
19: // defining different strings
20:
21: $strings = array(
22: "",
23: '',
24: "\n",
25: '\n',
26: "hello\tworld\nhello\nworld\n",
27: 'hello\tworld\nhello\nworld\n',
28: "1234hello45world\t123",
29: '1234hello45world\t123',
30: "hello\0world\012",
31: 'hello\0world\012',
32: chr(0).chr(0),
33: chr(0)."hello\0world".chr(0),
34: chr(0).'hello\0world'.chr(0),
35: "hello".chr(0)."world",
36: 'hello'.chr(0).'world',
37: "hello\0\100\xaaaworld",
38: 'hello\0\100\xaaaworld'
39: );
40:
41: $mask = "sft\n34lw56r78d90\0\xaa\100o";
42:
43:
44: // loop through each element of the array for str argument
45:
46: foreach($strings as $str) {
47: echo "\n-- Iteration with str value \"$str\" --\n";
48:
49: //calling strcspn() with default arguments
50: var_dump( strcspn($str,$mask) );
51: };
52:
53: echo "Done"
54: ?>
55: --EXPECTF--
56: *** Testing strcspn() : with different str and default start and len args ***
57:
58: -- Iteration with str value "" --
59: int(0)
60:
61: -- Iteration with str value "" --
62: int(0)
63:
64: -- Iteration with str value "
65: " --
66: int(0)
67:
68: -- Iteration with str value "\n" --
69: int(2)
70:
71: -- Iteration with str value "hello world
72: hello
73: world
74: " --
75: int(2)
76:
77: -- Iteration with str value "hello\tworld\nhello\nworld\n" --
78: int(2)
79:
80: -- Iteration with str value "1234hello45world 123" --
81: int(2)
82:
83: -- Iteration with str value "1234hello45world\t123" --
84: int(2)
85:
86: -- Iteration with str value "hello world
87: " --
88: int(2)
89:
90: -- Iteration with str value "hello\0world\012" --
91: int(2)
92:
93: -- Iteration with str value "