search
Homephp教程php手册让php支持yar.packager,可以实现文字高亮的效果

1、安装msgpack、yar、yaf三个php扩展

2、编译yar的时候,使用./configure --enable-msgpack --with-php-config=/usr/local/php/bin/pgp-config参数,--enable-msgpack参数是开启packager对yar的支持

3、php -i|grep msgpack,如果有yar.packager => msgpack => msgpack说明yar已经支持了msgpack

4、测试页面
class YarCheckKeyword {
protected static $HOSTNAME = 'kwdt.yarc.service.weibo.com';
protected static $PORT = '7002';
/**
*
* 请求Kwdt Server
*
* @param string $text 文本字符串
*
* @param array $types 关键词类型
*
* @param int $return_text 是否返回命中的关键词 1.是 0.否 这里不需要返回
*
* @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($a);

5、上述代码保存成文件,使用php执行,测试结果为下面内容说明成功
Array
(
[0] => -1
[1] => no keyword occured
)



Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools