修改cnki搜索的正则,解决搜索第一个结果的匹配问题

This commit is contained in:
wlx 2011-11-28 14:43:37 +00:00
parent f9fb991179
commit df287e4549
1 changed files with 4 additions and 3 deletions

View File

@ -944,8 +944,9 @@ class ServiceController extends Zend_Controller_Action
curl_close($ch);
$rev = array();
$max = 5;
if(preg_match_all("#<a.+? class=\"acticle\" href=\"(.+?)\".*?>(.+?)</a>#i",$body,$matchs,PREG_PATTERN_ORDER))
$max = 5;
$error='';
if(preg_match_all("#<a\sclass=\"acticle\" href=\"(.+?)\".*?>(.+?)<\/a>#im",$body,$matchs,PREG_PATTERN_ORDER))
{
foreach ($matchs[2] as $k=>$v){
if($k < $max) $rev[$k]['title']=$v;
@ -957,7 +958,7 @@ class ServiceController extends Zend_Controller_Action
$error = "无搜索结果";
}
if(preg_match_all("#<span class=\"search_result_snap\" >(.+?)</span>#i",$body,$matchs,PREG_PATTERN_ORDER))
if(preg_match_all("#<span class=\"search_result_snap\" >(.+?)<\/span>#im",$body,$matchs,PREG_PATTERN_ORDER))
{
foreach ($matchs[1] as $k=>$v){
if($k < $max) $rev[$k]['content']=$v;