-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.php
More file actions
32 lines (23 loc) · 1.18 KB
/
demo.php
File metadata and controls
32 lines (23 loc) · 1.18 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
<?php
require 'CharsetConvertor.php';
define('ROOT_PATH', dirname(__FILE__));
// source ansi
$str = file_get_contents(ROOT_PATH.'/test_data/ansi.txt');
// source utf8
$utf8_source_str = file_get_contents(ROOT_PATH.'/test_data/utf8.txt');
// convert UTF-8 to ANSI
$ansi_str = CharsetConvertor::convert($utf8_source_str, CharsetConvertor::UTF8, CharsetConvertor::ANSI);
// convert ANSI to UTF-8
$utf8_str = CharsetConvertor::convert($str, CharsetConvertor::ANSI, CharsetConvertor::UTF8);
// convert ANSI to UTF-8+Bom
$utf8bom_str = CharsetConvertor::convert($str, CharsetConvertor::ANSI, CharsetConvertor::UTF8BOM);
// convert ANSI to UTF-16
$utf16_str = CharsetConvertor::convert($str, CharsetConvertor::ANSI, CharsetConvertor::UTF16);
// convert ANSI to UTF-16 Big Endian
$utf16be_str = CharsetConvertor::convert($str, CharsetConvertor::ANSI, CharsetConvertor::UTF16BE);
// 将转换后的数据写入文件
file_put_contents('/tmp/convert_ansi.txt', $ansi_str);
file_put_contents('/tmp/convert_utf8.txt', $utf8_str);
file_put_contents('/tmp/convert_utf8-bom.txt', $utf8bom_str);
file_put_contents('/tmp/convert_utf16.txt', $utf16_str);
file_put_contents('/tmp/convert_utf16-be.txt', $utf16be_str);