Allow php to support yar. packager to achieve text highlighting. _ PHP Tutorial

Source: Internet
Author: User
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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.