ホームページ  >  記事  >  バックエンド開発  >  PHP で yar.packager をサポートしてテキストの強調表示効果を実現する_PHP チュートリアル

PHP で yar.packager をサポートしてテキストの強調表示効果を実現する_PHP チュートリアル

WBOY
WBOYオリジナル
2016-07-13 10:31:56944ブラウズ

1. 3 つの PHP 拡張機能 msgpack、yar、yaf をインストールします。

2. yar をコンパイルするときに、./configure --enable-msgpack --with-php-config=/usr/local/php/bin/pgp- を使用します。 config パラメーターである --enable-msgpack パラメーターは、パッケージャーの 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';
/**
*
* Request Kwdt Server
*
* @param string $text 文字列
*
* @param array $types キーワードの種類
*
* @param int $return_text ヒットしたキーワードを返すかどうか 1. Yes 0 .No 、ここで戻る必要はありません
*
* @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 namesn";
}
$funcname = "検出";
$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='aaaaaaaaaa';
$obj=new YarCheckKeyword();
$a=$obj->connectKwdt_Server($text);
print_r( $a);

5. 上記のコードをファイルに保存し、php を使用して実行します。テスト結果は次のようになります。
Array
(
[0] => -1
[1] =>キーワードは発生しませんでした
)



www.bkjia.comtru​​ehttp://www.bkjia.com/PHPjc/760154.html技術記事 1. 3 つの PHP 拡張機能 (msgpack、yar、yaf) をインストールします。 2. yar をコンパイルするときに、./configure --enable-msgpack --with-php-config=/usr/local/php/bin/pgp-config を使用します。パラメータ。 --enable-msgpack パラメータ...
声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。