Menu

[r753]: / branches / jostb-debian-ubuntu-patch / php-java-bridge / tests.php5 / utf8-1.php  Maximize  Restore  History

Download this file

50 lines (33 with data), 1.4 kB

 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
#!/usr/bin/php
# For the following test start the java VM with:
# java -Dfile.encoding=ASCII -jar JavaBridge.jar INET:0 4 ""
# and run the test as follows:
# php utf8-1.inc | grep '^Gr' | od -c
# =>
# 0000000 G r 303 274 303 237 G o t t \n G r ? ?
# 0000020 G o t t \n G r 374 337 G o t t \n
<?php
if (!extension_loaded('java')) {
if (!(require_once("http://127.0.0.1:8080/JavaBridge/java/Java.inc"))) {
echo "java extension not installed.";
exit(2);
}
}
java_set_file_encoding("ISO-8859-1");
// the following is rewritten into new String(..., "ISO-8859-1");
$string = new Java("java.lang.String", "Grüß Gott");
// decode string into UTF-8
print java_values($string->getBytes("UTF-8")) . "\n";
// decode string using System.getProperty("file.encoding");
print java_values($string->getBytes()) . "\n";
// decode string using file encoding
print java_values($string->toString()) . "\n";
// the following is rewritten into new String(..., "ISO-8859-1");
$string = new Java("java.lang.String", "Grüß Gott", 0, 9);
// decode string into UTF-8
print java_values($string->getBytes("UTF-8")) . "\n";
// decode string using System.getProperty("file.encoding");
print java_values($string->getBytes()) . "\n";
// decode string using file encoding
print java_values($string->toString()) . "\n";
?>
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.