以下代码: <?php // $Id: test2.php 910 2007-11-16 11:43:46Z shodan $ require ( "api/sphinxapi.php" );
$docs = array ( "this is my test 我们 to be highlighted 抄袭我们, and for the sake of the testing we need to pump its length somewhat", "another 抄袭我们 test 我们 to be highlighted, below limit", "test number three 我们 , without phrase match", "final test, 我们 not only without phrase match, but also above limit and with swapped phrase text test as well", ); $words = "抄袭"; // $cm=new GB2312UTF8(); // $words = $cm->GB2312TOUTF8($words); // echo $words; $index = "test_search"; $opts = array ( "before_match" => "<b>", "after_match" => "</b>", "chunk_separator" => " ... ", "limit" => 60, "around" => 3, );
foreach ( array( 0, 1 ) as $exact ) { $opts["exact_phrase"] = $exact; print "exact_phrase=$exact\n";
$cl = new SphinxClient (); $cl->SetServer( '127.0.0.1', 3312 ); $res = $cl->BuildExcerpts ( $docs, $index, $words, $opts ); if ( !$res ) { die ( "ERROR: " . $cl->GetLastError() . ".\n" ); } else { $n = 0; foreach ( $res as $entry ) { $n++; print iconv('UTF-8','GBK',"n=$n, res=$entry\n"); } print "\n"; } }
// // $Id: test2.php 910 2007-11-16 11:43:46Z shodan $ //
?>
测试结果: ---------- PHP5 代码调试 ---------- exact_phrase=0 n=1, res=this is my test 我们 to be highlighted 抄袭我们, and for the sake ... n=2, res=another <b>抄袭</b>我们 test 我们 to be highlighted, below limit n=3, res=test number three 我们 , without phrase match n=4, res=final test, 我们 not only without phrase match, but also ...
exact_phrase=1 n=1, res=this is my test 我们 to be highlighted 抄袭我们, and for the sake ... n=2, res=another <b>抄袭</b>我们 test 我们 to be highlighted, below limit n=3, res=test number three 我们 , without phrase match n=4, res=final test, 我们 not only without phrase match, but also ...
输出完毕 (耗时 0 秒) - 正常终止
请注意: 我的php文件的字符集为UTF-8
你那边是否字符集不正确? |