Php supports yar. packager to highlight text. 1. install three php extensions: msgpack, yar, and yaf. 2. compile yar and use them. configure -- enable-msgpack -- with-php-configusrlocalphpbinpgp-config parameter, -- enable-msgpack parameter 1. install three php extensions: msgpack, yar, and yaf.
2. when compiling yar, use. /configure -- enable-msgpack -- with-php-config =/usr/local/php/bin/pgp-config parameter. the -- enable-msgpack parameter enables packager's support for yar.
3. php-I | grep msgpack. if yar. packager => msgpack is available, yar supports msgpack.
4. test page
Class YarCheckKeyword {
Protected static $ HOSTNAME = 'kwdt .yarc.service.weibo.com ';
Protected static $ PORT = '20140901 ';
/**
*
* Request Kwdt Server
*
* @ Param string $ text string
*
* @ Param array $ types keyword type
*
* @ Param int $ return_text whether to return the hit keyword 1. yes 0. no need to return here
*
* @ Return array
*
*/
Public function connectKwdt_Server ($ text, $ return_text = 1, $ types = array (1, 2, 3), $ withoutsass = false ){
If (! Class_exists ("Yar_client") |! $ Text |! $ Types ){
Return "yar_client no exists \ n ";
}
$ Funcname = "detect ";
$ Host = YarCheckKeyword: $ HOSTNAME;
$ Port = YarCheckKeyword: $ PORT;
Try {
$ Client = new Yar_Client ("tcp: // $ host: $ port ");
$ Response = $ client-> $ funcname ($ text, $ return_text, $ types );
Return $ response;
} Catch (Exception $ e ){
Print_r ($ e );
}
}
}
$ Text = 'aaaaaaaaaaa ';
$ Obj = new YarCheckKeyword ();
$ A = $ obj-> connectKwdt_Server ($ text );
Print_r ($ );
5. Save the above code as a file and run it in php. the test result shows that the code is successful.
Array
(
[0] =>-1
[1] => no keyword occured
)
Compile 2. when compiling yar, use. /configure -- enable-msgpack -- with-php-config =/usr/local/php/bin/pgp-config parameter, -- enable-msgpack parameter...