处理部分:
<?php header("Content-type:text/html;charset=utf-8"); require 'QueryList/QueryList.class.php'; $url = "http://www.hkxy.edu.cn/"; $reg = array( "title" => array("td>a","text"), "src" => array("td>a","href"), ); //$rang = "[id^=post-]"; $hj = QueryList::Query($url,$reg); //$hj = QueryList::Query($url,$reg,$rang); for($i=0;$i<count($hj->jsonArr);$i++){ //$hj->jsonArr[$i]['title']=html_entity_decode(($hj->jsonArr[$i]['title']),ENT_NOQUOTES,'utf-8'); $hj->jsonArr[$i]['title']=str_replace(' ','',$hj->jsonArr[$i]['title']); $hj->jsonArr[$i]['title']=iconv('gbk', 'utf-8', $hj->jsonArr[$i]['title']); $hj->jsonArr[$i]['src']='http://www.hkxy.edu.cn'.$hj->jsonArr[$i]['src']; } //print_r($hj->jsonArr); for($i=0;$i<5;$i++){ $arr['news1'][$i]=$hj->jsonArr[$i]; $arr['news2'][$i]=$hj->jsonArr[$i+17]; $arr['news3'][$i]=$hj->jsonArr[$i+25]; } //print_r($arr); $str=json_encode($arr); function arrayRecursive(&$array, $function, $apply_to_keys_also = false) { static $recursive_counter = 0; if (++$recursive_counter >1000 ) { die('possible deep recursion attack'); } foreach ($array as $key => $value) { if (is_array($value)) { arrayRecursive($array[$key], $function, $apply_to_keys_also); } else { $array[$key] = $function($value); } if ($apply_to_keys_also && is_string($key)) { $new_key = $function($key); if ($new_key != $key) { $array[$new_key] = $array[$key]; unset($array[$key]); } } } $recursive_counter--; } /************************************************************** * * 将数组转换为JSON字符串(兼容中文) * @param array $array 要转换的数组 * @return string 转换得到的json字符串 * @access public * *************************************************************/ function JSON($array) { arrayRecursive($array, 'urlencode', true); $json = json_encode($array); return urldecode($json); } echo JSON($arr); //echo $hj->getJSON();