Annotation of embedaddon/php/ext/standard/tests/strings/chr_ord.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test 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: */
11: echo "*** Testing ord() & chr() basic operations ***\n";
12: for($i=0; $i<256; $i++) echo !ord(chr($i)) == $i;
13:
14: /* miscelleous input */
15: echo "\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;
38: foreach($arr_test as $var){
39: echo "-- Iteration $counter --\n";
40: var_dump( chr($var) );
41: $counter++;
42: }
43:
44: echo "\n*** Testing ord() usage variations ***\n";
45: $counter=1;
46: foreach($arr_test as $var){
47: echo "-- Iteration $counter --\n";
48: var_dump( ord($var) );
49: $counter++;
50: }
51:
52: /* Error conditions */
53: echo "\n*** Testing chr() error conditions ***\n";
54: //zero arguments
55: var_dump( chr() );
56: // more than expected no. of args
57: var_dump( chr($arr_test[0], $arr_test[1]) );
58:
59:
60: echo "\n*** Testing ord() error conditions ***\n";
61: // zero arguments
62: var_dump( ord() );
63: // more than expected no. of args
64: var_dump( ord($arr_test[0], $arr_test[1]) );
65:
66: echo "Done\n";
67: ?>
68: --EXPECTF--
69: *** Testing ord() & chr() basic operations ***
70:
71: *** Testing chr() usage variations ***
72: -- Iteration 1 --
73: string(1) "