修改cnki搜索的正则,解决搜索第一个结果的匹配问题
This commit is contained in:
parent
f9fb991179
commit
df287e4549
|
@ -944,8 +944,9 @@ class ServiceController extends Zend_Controller_Action
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
|
|
||||||
$rev = array();
|
$rev = array();
|
||||||
$max = 5;
|
$max = 5;
|
||||||
if(preg_match_all("#<a.+? class=\"acticle\" href=\"(.+?)\".*?>(.+?)</a>#i",$body,$matchs,PREG_PATTERN_ORDER))
|
$error='';
|
||||||
|
if(preg_match_all("#<a\sclass=\"acticle\" href=\"(.+?)\".*?>(.+?)<\/a>#im",$body,$matchs,PREG_PATTERN_ORDER))
|
||||||
{
|
{
|
||||||
foreach ($matchs[2] as $k=>$v){
|
foreach ($matchs[2] as $k=>$v){
|
||||||
if($k < $max) $rev[$k]['title']=$v;
|
if($k < $max) $rev[$k]['title']=$v;
|
||||||
|
@ -957,7 +958,7 @@ class ServiceController extends Zend_Controller_Action
|
||||||
$error = "无搜索结果";
|
$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){
|
foreach ($matchs[1] as $k=>$v){
|
||||||
if($k < $max) $rev[$k]['content']=$v;
|
if($k < $max) $rev[$k]['content']=$v;
|
||||||
|
|
Loading…
Reference in New Issue