-
Notifications
You must be signed in to change notification settings - Fork 1
/
sample-oop.php
70 lines (64 loc) · 2.3 KB
/
sample-oop.php
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
#!/usr/bin/php
<?php
if ( ! extension_loaded ('chardet') ) {
fprintf (STDERR, "Chardet module not loaded!\n");
exit (1);
}
$strings = array (
'안녕하세요 abc는 영어고요, 가나다는 한글 입니다.',
'안녕',
'안녕하세요',
'조금더 길게 적어 봅니다. 어느 정도가 필요할까요? 오호라.. 점점 길어지네',
);
try {
$chardet = new CHARDET ();
$i=0;
foreach ( $strings as $s ) {
#
# proto object chardet_detect (stream handle, string[, mode])
# database handle : return value of chardet_open () API
# string : strings for character set detecting
# mode : optional
# if support CHARDTE_MOZ, this value is
# default, and don't support CHARDET_MOZ,
# CHARDET_ICU is default.
#
# CHARDET_MOZ : libchardet library result
# CHARDET_ICU : icu library result
# CHARDET_PY : python-chardet result
#
# if each CHARDET_(MOZ|ICU|PY) value is -1,
# it means don't support each mode.
#
# return value type : object -> encoding : detecting charset name
# langs : charset language name
# Don't support on CHARDET_MOZ and CAHRDET_PY mode
# confidence : detecting confidence
# status : error code (0 is not error)
#
if ( CHARDET_MOZ != -1 )
$moz = $chardet->detect ($s);
if ( CHARDET_ICU != -1 )
$icu = $chardet->detect ($s, CHARDET_ICU);
if ( CHARDET_PY != -1 )
$py = $chardet->detect ($s, CHARDET_PY);
echo "$s\n";
if ( CHARDET_MOZ != -1 )
printf ("MOZ : Encoding -> %-12s, Confidence -> %3d, Status -> %d\n",
$moz->encoding, $moz->confidence, $moz->status);
if ( CHARDET_ICU != -1 )
printf ("ICU : Encoding -> %-12s, Confidence -> %3d, Status -> %d\n",
$icu->encoding, $icu->confidence, $icu->status);
if ( CHARDET_PY != -1 )
printf ("PY : Encoding -> %-12s, Confidence -> %3d, Status -> %d\n",
$py->encoding, $py->confidence, $py->status);
echo "\n";
$i++;
}
$chardet->close ();
} catch ( ChardetException $e ) {
fprintf (STDERR, "%s\n", $e->getMessage ());
$err = preg_split ('/\r?\n/', $e->getTraceAsString ());
print_r ($err);
}
?>