1--TEST--
2Test chr() and ord() functions
3--FILE--
4<?php
5/* Prototype: string chr ( int $ascii );
6   Description: Returns a one-character string containing the character specified by ascii.
7
8   Prototype: int ord ( string $string );
9   Description: Returns the ASCII value of the first character of string
10*/
11echo "*** Testing ord() & chr() basic operations ***\n";
12for($i=0; $i<256; $i++) echo !ord(chr($i)) == $i;
13
14/* miscelleous input */
15echo "\n*** Testing chr() usage variations ***\n";
16$arr_test = array(
17  "true",
18  "false",
19  true,
20  false,
21  "",
22  " ",
23  "a",
24  299,
25  321,
26  NULL,
27  '\0',
28  "0",
29  -312,
30  12.999,
31  -1.05009,
32  1100011,
33  "aaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbccccccccccccccccccccccccccccccdddddddddddddddddddddddddddddddddddddddddd",
34  "abcd\nabcd\tabcd\0abcd\rabcdNULLabcdefgh",
35  "abcd\x00abcd\x00abcd\x00abcdefghij",
36);
37$counter=1;
38foreach($arr_test as $var){
39  echo "-- Iteration $counter --\n";
40  var_dump( chr($var) );
41  $counter++;
42}
43
44echo "\n*** Testing ord() usage variations ***\n";
45$counter=1;
46foreach($arr_test as $var){
47  echo "-- Iteration $counter --\n";
48  var_dump( ord($var) );
49  $counter++;
50}
51
52/* Error conditions */
53echo "\n*** Testing chr() error conditions ***\n";
54//zero arguments
55var_dump( chr() );
56// more than expected no. of args
57var_dump( chr($arr_test[0], $arr_test[1]) );
58
59
60echo "\n*** Testing ord() error conditions ***\n";
61// zero arguments
62var_dump( ord() );
63// more than expected no. of args
64var_dump( ord($arr_test[0], $arr_test[1]) );
65
66echo "Done\n";
67?>
68--EXPECTF--
69*** Testing ord() & chr() basic operations ***
70
71*** Testing chr() usage variations ***
72-- Iteration 1 --
73string(1) "�"
74-- Iteration 2 --
75string(1) "�"
76-- Iteration 3 --
77string(1) ""
78-- Iteration 4 --
79string(1) "�"
80-- Iteration 5 --
81string(1) "�"
82-- Iteration 6 --
83string(1) "�"
84-- Iteration 7 --
85string(1) "�"
86-- Iteration 8 --
87string(1) "+"
88-- Iteration 9 --
89string(1) "A"
90-- Iteration 10 --
91string(1) "�"
92-- Iteration 11 --
93string(1) "�"
94-- Iteration 12 --
95string(1) "�"
96-- Iteration 13 --
97string(1) "�"
98-- Iteration 14 --
99string(1) ""
100-- Iteration 15 --
101string(1) "�"
102-- Iteration 16 --
103string(1) "�"
104-- Iteration 17 --
105string(1) "�"
106-- Iteration 18 --
107string(1) "�"
108-- Iteration 19 --
109string(1) "�"
110
111*** Testing ord() usage variations ***
112-- Iteration 1 --
113int(116)
114-- Iteration 2 --
115int(102)
116-- Iteration 3 --
117int(49)
118-- Iteration 4 --
119int(0)
120-- Iteration 5 --
121int(0)
122-- Iteration 6 --
123int(32)
124-- Iteration 7 --
125int(97)
126-- Iteration 8 --
127int(50)
128-- Iteration 9 --
129int(51)
130-- Iteration 10 --
131int(0)
132-- Iteration 11 --
133int(92)
134-- Iteration 12 --
135int(48)
136-- Iteration 13 --
137int(45)
138-- Iteration 14 --
139int(49)
140-- Iteration 15 --
141int(45)
142-- Iteration 16 --
143int(49)
144-- Iteration 17 --
145int(97)
146-- Iteration 18 --
147int(97)
148-- Iteration 19 --
149int(97)
150
151*** Testing chr() error conditions ***
152
153Warning: Wrong parameter count for chr() in %s on line %d
154NULL
155
156Warning: Wrong parameter count for chr() in %s on line %d
157NULL
158
159*** Testing ord() error conditions ***
160
161Warning: ord() expects exactly 1 parameter, 0 given in %s on line %d
162NULL
163
164Warning: ord() expects exactly 1 parameter, 2 given in %s on line %d
165NULL
166Done
167