git clone https://github.com/BYVoid/OpenCC.git
cd OpenCC
make
sudo make install
git clone https://github.com/NauxLiu/opencc4php.git
cd opencc4php
phpize
./configure
make
sudo make install
cd /etc/php5/mods-available
vim opencc.ini
; configuration for php opencc module
; priority=20
extension=opencc.so
cd /etc/php5/php-cli/conf.d
ln -s ../../mods-available/opencc.ini 20-opencc.ini
cd /etc/php5/php-fpm/conf.d
ln -s ../../mods-available/opencc.ini 20-opencc.ini
<?php
class Chinese {
private static $openccFp = array();
private static function convert($str, $name) {
if (!self::$openccFp[$name]) {
self::$openccFp[$name] = opencc_open($name.".json");
}
return opencc_convert($str, self::$openccFp[$name]);
}
public static function sc2tc($str) {
return self::convert($str, "s2twp");
}
public static function tc2sc($str) {
return self::convert($str, "tw2s");
}
}
?>
沒有留言:
張貼留言