安裝php擴展trie_filter


php擴展trie_filter是一個用來在項目中需要對用戶傳遞過來的文字進行過濾敏感詞

安裝基礎類庫

關鍵詞過濾擴展,用於檢查一段文本中是否出現敏感詞,基於Double-Array Trie 樹實現
安裝 libdatrie , 需要 libdatrie-0.2.4 或更新的版本
它依賴 libiconv .

1 安裝libiconv

wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz tar -zxf libiconv-1.14.tar.gz cd libiconv-1.14 ./configure make && make install 

中間問題
In file included from progname.c:26:0: ./stdio.h:1010:1: error: ‘gets’ undeclared here (not in a function) _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead"); ^ make[2]: *** [progname.o] Error 1 make[2]: Leaving directory `/usr/local/src/zabbix-2.4.7/libiconv-1.14/srclib' make[1]: *** [all] Error 2 make[1]: Leaving directory `/usr/local/src/zabbix-2.4.7/libiconv-1.14/srclib' make: *** [all] Error 2

  解決方法
    vim libiconv-1.14/srclib/stdio.in.h
    將689行代碼:_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");替換為

    #if defined(__GLIBC__) && !defined(__UCLIBC__) && !__GLIBC_PREREQ(2, 16)        _GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");     #endif

2.安裝libdatrie
 
        
wget ftp://linux.thai.net/pub/ThaiLinux/software/libthai/libdatrie-0.2.4.tar.gz tar -zxf libdatrie-0.2.4.tar.gz cd libdatrie-0.2.4 ./configure --prefix=/usr/local/libdatrie/ make ICONV_LIBS='/usr/local/lib/libiconv.so' make install 

安裝PHP擴展

  一般安裝擴展時需要使用phpize進行設置配置
  如果沒有需要 apt-get install php-dev
  我的是php7.2 所以需要apt-get install php7.2-dev
  源代碼只兼容到5.3,然后又找到了新的包 https://github.com/zzjin/php-ext-trie-filter/tree/php7

 

 

  wget https://github.com/wulijun/php-ext-trie-filter/archive/master.zip   unzip master.zip   cd php-ext-trie-filter-master/   phpize   ./configure --with-php-config=/usr/bin/php-config --with-trie_filter=/usr/local/libdatrie/   make && make install

php查找方法whereis php-config



配置

 
        

這個時候需要配置一下fpm和cli
vim /etc/php/7.2/cli/php.ini
再最后一行加入

 
        
[trie_filter] extension=trie_filter.so 
 
        

fpm相同操作

 
        

service php7.2-fpm restart 重啟php

 
        

然后再使用php -m查看擴展

 

 
        

 


 

 
 
        



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM