直接上代码
<?php
require 'libs/config.inc.php';
$ch = curl_init("http://opac.hhit.edu.cn:8080/opac/openlink.php?strSearchType=title&strText=天才&displaypg=1000&sort=CATA_DATE&showmode=table");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // 获取数据返回
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true); // 在启用 CURLOPT_RETURNTRANSFER 时候将获取数据返回
$output = curl_exec($ch);
$output = preg_match('/<table width="100%" border="0" cellpadding="5" cellspacing="1" bgcolor="#CCCCCC" class="table_line" id="result_content" >(.*)<\/table>/isu', $output, $arr);
$output = preg_replace("'<tr[^>]*?>'si","",$arr[0]);
$output = preg_replace("'<table[^>]*?>'si","",$output);
$output = preg_replace("'<span[^>]*?>'si","",$output);
$output = preg_replace("'<td[^>]*?>'si","",$output);
$output = preg_replace("'</td>'si","",$output);
$output = preg_replace("'</span>'si","",$output);
$output = str_replace("</tr>","{tr}",$output);
$output = str_replace("\t","",$output);
$output = str_replace(" ","",$output);
$output = preg_replace('/ /',"",$output);
$output = preg_replace("'<[/!]*?[^<>]*?>'si","",$output);
$output = explode('{tr}', $output);
array_pop($output); //去除数组最后一个空元素
foreach ($output as $key => $value) {
$value = trim($value);
$temp = explode("\r\n",$value);
$output[$key] = $temp;
}
array_shift($output);
print_r($output);
exit;
$smarty->assign('arr',$output); //数组定义模板
$smarty->display('lib.html');
?>
想要去除红字的元素
Array
(
[0] => Array
(
[0] => 1
[1] => 天才少年维克多
[2] => (美) 乔辛·迪·波沙达, 雷蒙德·乔伊著
[3] => 南海出版公司2014.06
[4] => I712.45/965
[5] => 中文图书
)
[1] => Array
(
[0] => 2
[1] => 维特根斯坦传:天才之为责任.插图本
[2] => (英) 瑞·蒙克著
[3] => 浙江大学出版社2014.04
[4] => B561.59/14
[5] => 中文图书
)
)
分不多,全给了,十分感谢!
------解决思路----------------------
foreach($output as $k => $v) {
unset($output[$k][2], $output[$k][3]);
}