Git Product home page Git Product logo

ffi-pinyin's Introduction

ffi-pinyin

该项目是将中文汉字转换成拼音,使用rust构建动态链接库来给php调用。 该库主要是为了提高php转换中文拼音的性能而构建(特别是长文章)。

环境

需要php >= 7.4 以上的版本并且开启了FFI扩展。如果你需要自己编译库还需要装rust 工具链。

还需要设置php.ini 中的ffi.enableOn

Usage

该库提供四种基础用法:不带音标,带音标,首字母,多音字带音标。

<?php

include __DIR__ . '/../src/Pinyin.php';

$py = FastFFI\Pinyin\Pinyin::new();

echo "无音标: ", $py->plain("**人..."), "\n";
echo "首字母: ", $py->letter("**人"), "\n";
echo "音标: ", $py->tone("**人"), "\n";
echo "多音音标:", $py->tone_multi("**人"), "\n";

以上程序执行后的结果:

无音标: zhong guo ren - - -

首字母: z g r

音标: zhōng guó rén

多音音标:zhōng:zhòng guó rén

转换后的多个拼音都是以" "空格隔开,不能识别的字符都是以-来代替,多音字是以:来连接的。

FAQ

  • centos上执行失败?

    确定是不是glibc版本过低。可以使用ldd lib/libffi_pinyin.so 来查看库信息。 如果出现/lib64/libc.so.6: version 'glibc_2.18' not found就说明你服务的glibc版本过低。 下载glibc编译升级,下载地址: wget http://mirrors.ustc.edu.cn/gnu/libc/glibc-2.18.tar.gz

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.