1--TEST--
2Test strncmp() function: usage variations - case-sensitivity
3--FILE--
4<?php
5/* Prototype  : int strncmp ( string $str1, string $str2, int $len );
6 * Description: Binary safe case-sensitive string comparison of the first n characters
7 * Source code: Zend/zend_builtin_functions.c
8*/
9
10/* Test strncmp() function with upper-case and lower-case alphabets as inputs for 'str1' and 'str2' */
11
12echo "*** Test strncmp() function: with alphabets ***\n";
13echo "-- Passing upper-case letters for 'str1' --\n";
14for($ASCII = 65; $ASCII <= 90; $ASCII++) {
15  var_dump( strncmp( chr($ASCII), chr($ASCII), 1 ) );  //comparing uppercase letters with uppercase letters; exp: int(0)
16  var_dump( strncmp( chr($ASCII), chr($ASCII + 32), 1 ) );  //comparing uppercase letters with lowercase letters; exp: value < 0
17}
18
19echo "\n-- Passing lower-case letters for 'str1' --\n";
20for($ASCII = 97; $ASCII <= 122; $ASCII++) {
21  var_dump( strncmp( chr($ASCII), chr($ASCII), 1 ) );  //comparing lowercase letters with lowercase letters; exp: int(0)
22  var_dump( strncmp( chr($ASCII), chr($ASCII - 32), 1 ) );  //comparing lowercase letters with uppercase letters; exp: value > 0
23}
24echo "*** Done ***";
25?>
26--EXPECTREGEX--
27\*\*\* Test strncmp\(\) function: with alphabets \*\*\*
28-- Passing upper-case letters for 'str1' --
29int\(0\)
30int\(-[1-9][0-9]*\)
31int\(0\)
32int\(-[1-9][0-9]*\)
33int\(0\)
34int\(-[1-9][0-9]*\)
35int\(0\)
36int\(-[1-9][0-9]*\)
37int\(0\)
38int\(-[1-9][0-9]*\)
39int\(0\)
40int\(-[1-9][0-9]*\)
41int\(0\)
42int\(-[1-9][0-9]*\)
43int\(0\)
44int\(-[1-9][0-9]*\)
45int\(0\)
46int\(-[1-9][0-9]*\)
47int\(0\)
48int\(-[1-9][0-9]*\)
49int\(0\)
50int\(-[1-9][0-9]*\)
51int\(0\)
52int\(-[1-9][0-9]*\)
53int\(0\)
54int\(-[1-9][0-9]*\)
55int\(0\)
56int\(-[1-9][0-9]*\)
57int\(0\)
58int\(-[1-9][0-9]*\)
59int\(0\)
60int\(-[1-9][0-9]*\)
61int\(0\)
62int\(-[1-9][0-9]*\)
63int\(0\)
64int\(-[1-9][0-9]*\)
65int\(0\)
66int\(-[1-9][0-9]*\)
67int\(0\)
68int\(-[1-9][0-9]*\)
69int\(0\)
70int\(-[1-9][0-9]*\)
71int\(0\)
72int\(-[1-9][0-9]*\)
73int\(0\)
74int\(-[1-9][0-9]*\)
75int\(0\)
76int\(-[1-9][0-9]*\)
77int\(0\)
78int\(-[1-9][0-9]*\)
79int\(0\)
80int\(-[1-9][0-9]*\)
81
82-- Passing lower-case letters for 'str1' --
83int\(0\)
84int\([1-9][0-9]*\)
85int\(0\)
86int\([1-9][0-9]*\)
87int\(0\)
88int\([1-9][0-9]*\)
89int\(0\)
90int\([1-9][0-9]*\)
91int\(0\)
92int\([1-9][0-9]*\)
93int\(0\)
94int\([1-9][0-9]*\)
95int\(0\)
96int\([1-9][0-9]*\)
97int\(0\)
98int\([1-9][0-9]*\)
99int\(0\)
100int\([1-9][0-9]*\)
101int\(0\)
102int\([1-9][0-9]*\)
103int\(0\)
104int\([1-9][0-9]*\)
105int\(0\)
106int\([1-9][0-9]*\)
107int\(0\)
108int\([1-9][0-9]*\)
109int\(0\)
110int\([1-9][0-9]*\)
111int\(0\)
112int\([1-9][0-9]*\)
113int\(0\)
114int\([1-9][0-9]*\)
115int\(0\)
116int\([1-9][0-9]*\)
117int\(0\)
118int\([1-9][0-9]*\)
119int\(0\)
120int\([1-9][0-9]*\)
121int\(0\)
122int\([1-9][0-9]*\)
123int\(0\)
124int\([1-9][0-9]*\)
125int\(0\)
126int\([1-9][0-9]*\)
127int\(0\)
128int\([1-9][0-9]*\)
129int\(0\)
130int\([1-9][0-9]*\)
131int\(0\)
132int\([1-9][0-9]*\)
133int\(0\)
134int\([1-9][0-9]*\)
135\*\*\* Done \*\*\*
136