summaryrefslogtreecommitdiff
path: root/ext/mbstring/tests/015.inc
blob: ca7f9dedd3fb120f9e30e36ae16f7dcb829d7854 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
// TODO: Add more tests
//$debug = true; // Uncomment this line to view error/warning/notice message in *.out file
ini_set('include_path','.');
include_once('common.inc');

// SJIS string (BASE64 encoded)
$sjis = base64_decode('k/qWe4zqg2WDTINYg2eCxYK3gUIwMTIzNIJUglWCVoJXgliBQg==');
// JIS string (BASE64 encoded)
$jis = base64_decode('GyRCRnxLXDhsJUYlLSU5JUgkRyQ5ISMbKEIwMTIzNBskQiM1IzYjNyM4IzkhIxsoQg==');
// EUC-JP string
$euc_jp = '日本語テキストです。0123456789。';

// Test for single scaler
echo "== SCALER TEST ==\n";
$s = $sjis;
$encoding = mb_convert_variables('EUC-JP', 'SJIS', $s);
print("$encoding\n"); // SJIS
print("$s\n"); // Converted to EUC-JP

$s = $jis;
$encoding = mb_convert_variables('EUC-JP', 'JIS', $s);
print("$encoding\n"); // JIS
print("$s\n"); // Converted to EUC-JP

$s = $euc_jp;
$encoding = mb_convert_variables('SJIS', 'EUC-JP', $s);
print("$encoding\n"); // EUC-JP
print(base64_encode($s)."\n"); // Converted to SJIS (base64 encoded)

$s = $euc_jp;
$encoding = mb_convert_variables('JIS', 'EUC-JP', $s);
print("$encoding\n"); // EUC-JP
print(base64_encode($s)."\n"); // Converted to JIS (base64 encoded)

// Test for multiple slcaler
$s1 = $euc_jp;
$s2 = $euc_jp;
$s3 = $euc_jp;
$encoding = mb_convert_variables('EUC-JP', 'auto', $s1, $s2, $s3);
print("$encoding\n"); // EUC-JP
print("$s1$s2$s3\n"); // Converted to EUC-JP



// Note: Mixing encoding in array/object is not supported?
// Test for array
echo "== ARRAY TEST ==\n";
$a = array($s3, $s2, $s1);
$aa = $a;
$encoding = mb_convert_variables('EUC-JP', 'auto', $aa);
print("$encoding\n"); // EUC-JP
print("{$aa[0]}{$aa[1]}{$aa[2]}\n"); // Converted to EUC-JP

$a = array($s1, $s2, $s3);
$aa = $a;
$encoding = mb_convert_variables('EUC-JP', 'auto', $aa);
print("$encoding\n"); // EUC-JP
print("{$aa[0]}{$aa[1]}{$aa[2]}\n"); // Converted to EUC-JP



// Test for object
echo "== OBJECT TEST ==\n";
class foo 
{
	var $s1;
	var $s2;
	var $s3;

	function foo() 
	{
		global $sjis, $jis, $euc_jp;
		
		$this->s1 = $euc_jp;
		$this->s2 = $euc_jp;
		$this->s3 = $euc_jp;
	}
}

class bar 
{
	var $s1;
	var $s2;
	var $s3;

	function bar() 
	{
		global $sjis, $jis, $euc_jp;
		
		$this->s1 = $euc_jp;
		$this->s2 = $euc_jp;
		$this->s3 = $euc_jp;
	}
}


$o = new foo;
$oo = $o;
$encoding = mb_convert_variables('EUC-JP', 'auto', $oo);
print("$encoding\n");   // EUC-JP
print("{$oo->s1}{$oo->s2}{$oo->s3}\n"); // Converted to EUC-JP

$o = new bar;
$oo = $o;
$encoding = mb_convert_variables('EUC-JP', 'auto', $oo);
print("$encoding\n"); // EUC-JP
print("{$oo->s1}{$oo->s2}{$oo->s3}\n"); // Converted to EUC-JP


// Test for scaler, array and object
echo "== SCALER, ARRAY AND OBJECT TEST ==\n";

$s1 = $euc_jp;
$s2 = $euc_jp;
$s3 = $euc_jp;
$aa = $a;
$oo = $o;

$encoding = mb_convert_variables('EUC-JP', 'auto', $s1, $s2, $s3, $aa, $oo);
print("$encoding\n"); // EUC-JP
print("$s1$s2$s3\n"); // Converted to EUC-JP
print("{$aa[0]}{$aa[1]}{$aa[2]}\n"); // Converted to EUC-JP
print("{$oo->s1}{$oo->s2}{$oo->s3}\n"); // Converted to EUC-JP


?>