Created
March 26, 2013 17:28
-
-
Save horsley/5247345 to your computer and use it in GitHub Desktop.
暨南大学图书馆搜书接口
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Created by JetBrains PhpStorm. | |
* User: Horsley | |
* Date: 12-4-30 | |
* Time: 下午3:47 | |
* To change this template use File | Settings | File Templates. | |
*/ | |
$act = $_GET['action']; | |
switch($act){ | |
case 'search': libSearch();break; | |
} | |
/** | |
* 书本搜索 | |
*/ | |
function libSearch(){ | |
$args = 'searchtype='.$_POST['searchtype']. '&searcharg=' .urlencode($_POST['searcharg']); | |
$ch =curl_init('http://202.116.13.244/search*chx/?'.$args); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
//curl_setopt($ch, CURLOPT_PROXY, '127.0.0.1:8888'); //调试,fiddler 本地代理 | |
$ret = curl_exec($ch); | |
//var_dump( curl_getinfo($ch)); | |
//var_dump(libSearchResultSimplifier( $ret)); | |
//libSearchResultSimplifier($ret); | |
$ret = libSearchResultSimplifier($ret); | |
$retHtml = ""; | |
foreach($ret as $item){ | |
$retHtml .= '<li><h3><a href="/server/jnulib.php?searchkey='; | |
$retHtml .= urlencode($_POST['searcharg']).'&resultid='.$item['resultid'].'">'; | |
$retHtml .= $item['bookname'].'</a></h3><p>'; | |
$retHtml .= $item['author'].'<br/>'.$item['booknum'].'</p></li>'; | |
} | |
$retHtml = '<ul data-role="listview">'.$retHtml.'</ul>'; | |
echo $retHtml; | |
} | |
/** | |
* 书本搜索结果页面处理 | |
* @param $pagedata 页面数据 | |
* @return array 处理过后的条目数组 | |
*/ | |
function libSearchResultSimplifier($pagedata){ | |
$items = explode('<td class="briefCitRow">', $pagedata); //头标记 | |
//echo $pagedata; | |
array_shift($items); | |
foreach($items as $resultid => &$tmp){ | |
$tmp = explode('<!--this is customized <screens/briefcit_chx.html>-->',$tmp); | |
array_pop($tmp); | |
$bookname = _getStrMid($tmp[0], '<span class="briefcitTitle">', '</a></span>'); | |
$tmp = array( | |
'bookname' => strip_tags( $bookname), | |
'resultid' => $resultid, | |
'author' => str_replace("著","",_getStrMid($tmp[0], ' / ', ' ')), | |
'press' => _getStrMid($tmp[0], ' ', ', '), | |
'booknum' => _getStrMid($tmp[0], 'E/browse">', '</a>'), | |
'bookisbn' => _getStrMid($tmp[0],'isbn=','&') | |
); | |
} | |
return $items; | |
} | |
/** | |
* 文本截取中间 | |
* @param $haystack 文本串 | |
* @param $leftSign 左标记 | |
* @param $rightSign 右标记 | |
* @return string 返回中间文本 | |
*/ | |
function _getStrMid($haystack, $leftSign, $rightSign) { | |
$tmpStrArr = explode($leftSign, $haystack, 2); | |
//echo $leftSign; | |
//print_r($tmpStrArr); | |
if(count($tmpStrArr) != 2) return ''; | |
$tmpStrArr = explode($rightSign, $tmpStrArr[1], 2); | |
if(count($tmpStrArr) != 2) return ''; | |
return $tmpStrArr[0]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment