PHP code example of meshell / ffi-opencc

1. Go to this page and download the library: Download meshell/ffi-opencc library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

meshell / ffi-opencc example snippets




w 方法支持opencc配置目录
$oc = \FastFFI\Opencc\OpenCC::new();

echo "简体转繁体: ", $oc->s2t("头可断,血可流"), "\n";

echo "繁体转简体: ", $oc->t2s("台湾省,是中華人民共和國法定的34個省級行政區之一,也是中華人民共和國法律上的两个岛屿省份之一,其轄區包括臺灣島及其附屬島嶼、澎湖列岛等地"), "\n";

echo "简体转台正繁体: ", $oc->s2tw("头可断,血可流"), "\n";

echo "台正繁体转简体: ", $oc->tw2s("台湾省,是中華人民共和國法定的34個省級行政區之一,也是中華人民共和國法律上的两个岛屿省份之一,其轄區包括臺灣島及其附屬島嶼、澎湖列岛等地"), "\n";

echo "简体转香港繁体: ", $oc->s2hk("头可断,血可流"), "\n";

echo "香港繁体转简体: ", $oc->hk2s("頭可斷,血可流"), "\n";