程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> 讓php支持yar.packager,可以實現文字高亮的效果

讓php支持yar.packager,可以實現文字高亮的效果

編輯:關於PHP編程

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、測試頁面
<?php
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
)



  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved