Annotation of embedaddon/php/ext/standard/tests/strings/strspn_variation9.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test strspn() function : usage variations - different strings with default start and len args
3: --FILE--
4: <?php
5: /* Prototype : proto int strspn(string str, string mask [, int start [, int len]])
6: * Description: Finds length of initial segment consisting entirely of characters found in mask.
7: If start or/and length is provided works like strspn(substr($s,$start,$len),$good_chars)
8: * Source code: ext/standard/string.c
9: * Alias to functions: none
10: */
11:
12: /*
13: * Testing strspn() : with different strings as str argument and default start and len args
14: */
15:
16: echo "*** Testing strspn() : 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 = "sfth12\ne34lw56r78d90\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 strspn() with default arguments
50: var_dump( strspn($str,$mask) );
51: };
52:
53: echo "Done"
54: ?>
55: --EXPECTF--
56: *** Testing strspn() : 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(1)
67:
68: -- Iteration with str value "\n" --
69: int(0)
70:
71: -- Iteration with str value "hello world
72: hello
73: world
74: " --
75: int(5)
76:
77: -- Iteration with str value "hello\tworld\nhello\nworld\n" --
78: int(5)
79:
80: -- Iteration with str value "1234hello45world 123" --
81: int(16)
82:
83: -- Iteration with str value "1234hello45world\t123" --
84: int(16)
85:
86: -- Iteration with str value "hello world
87: " --
88: int(12)
89:
90: -- Iteration with str value "hello\0world\012" --
91: int(5)
92:
93: -- Iteration with str value "